While I am importing the pandas in my data science project I am getting such kind of error. Does anyone know what might cause this?
I tried with re-installation of pandas and python also
I also tried with wheel
import numpy as np
import pandas as pd
AttributeError
Traceback (most recent call last)
<ipython-input-2-b231533e2331> in <module>
1 import numpy as np
----> 2 import pandas as pd
3 from imblearn.over_sampling import SMOTE
4 from sklearn.model_selection import train_test_split
5 from sklearn.neighbors import KNeighborsClassifier
AttributeError: 'property' object has no attribute '__name__'
"I got the solution for same. It may be multiple python version installation problem in same system problem so you need to create a virtual environment for your data science project now steps for creating virtual environment...."
1. install python 3.x
2. install pip
3. pip install virtualenv #for creating virtual environment
4. mkvirtualenv folder_name #command for creating virtual environment
5 pip install pandas # run this command in virtual environment directory
now import pandas it will work fine.
Related
I'm trying to generate a chart in online jupyter lab notebook and it is not allowing by throwing errors. Is it possible to do it there?
Thanks
[Updated the code and error]
import pandas as pd
import plotly.express as px
leads to the below error
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[28], line 2
1 import pandas as pd
----> 2 import plotly.express as px
ModuleNotFoundError: No module named 'plotly'
If you want to use package in jupyter notebook,
you should
install package by this line
!pip install package-name
then add new block to write code
import it in code
import package-name
(for someone if finding this question)
I have just installed gdal into my Python3 root environment using conda:
conda install -c conda-forge gdal
Installation went fine with the usual updates of some dependencies. Now returning to some of my scripts, both netCDF4 and mpl_toolkits.basemap have stopped working. These are the errors I get:
from netCDF4 import Dataset
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-7-09694a7f0e01> in <module>()
----> 1 from netCDF4 import Dataset
2 import numpy as np
3 import matplotlib.pyplot as plt
4 from scipy.interpolate import griddata
5 from mpl_toolkits.basemap import Basemap
/anaconda3/lib/python3.6/site-packages/netCDF4/__init__.py in <module>()
1 # init for netCDF4. package
2 # Docstring comes from extension module _netCDF4.
----> 3 from ._netCDF4 import *
4 # Need explicit imports for names beginning with underscores
5 from ._netCDF4 import __doc__, __pdoc__
ImportError: dlopen(/anaconda3/lib/python3.6/site-packages/netCDF4/_netCDF4.cpython-36m-darwin.so, 2): Library not loaded: #rpath/libhdf5.101.dylib
Referenced from: /anaconda3/lib/python3.6/site-packages/netCDF4/_netCDF4.cpython-36m-darwin.so
Reason: image not found
from mpl_toolkits.basemap import Basemap
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-8-5fb601138328> in <module>()
3 import matplotlib.pyplot as plt
4 from scipy.interpolate import griddata
----> 5 from mpl_toolkits.basemap import Basemap
6 import numpy.ma as ma
7 import glob
/anaconda3/lib/python3.6/site-packages/mpl_toolkits/basemap/__init__.py in <module>()
35 import numpy as np
36 import numpy.ma as ma
---> 37 import _geoslib
38 import functools
39
ImportError: dlopen(/anaconda3/lib/python3.6/site-packages/_geoslib.so, 2): Library not loaded: #rpath/libgeos-3.5.0.dylib
Referenced from: /anaconda3/lib/python3.6/site-packages/_geoslib.so
Reason: image not found
I have no idea what these errors mean, since those paths do exist. What is most baffling is that the netCDF4 and mpl_toolkits modules did not change (i.e. were not updated/downgraded) with the installation of gdal, so why now are they failing?
I'm at the end of my tether with problems like this. Fortunately I made a copy of my Python root directory before attempting this installation so I can now revert back to it (I've been here many times before).
I know about working in separate conda environments, but am I seriously supposed to install a new environment every time I want to use a new Python module? This not only takes up a lot of harddrive space but most inconveniently means adding new functionality to old codes is impossible (I want to use GDAL to plot some geotiffs using Basemap, which now does not work!).
I cannot imagine proficient Python users battling with these issues - so what am I doing wrong?
I wrote this code to load a dataset into a data frame. Dataset is given in a pickle file but it throws an error:
ModuleNotFoundError: No module named 'pandas.core.indexes'
import pickle
import pandas
dbfile = open(dataset loction,'rb')
df = pickle.load(dbfile)
I tried all the fixes given:
Updated the pandas
used df = pandas.read_picle(dataset location)
Tried installing pickle using pip but getting this error
C:\installs\WinPython-64bit-3.6.1.0Qt5\python-3.6.1.amd64>python -m pip install pickle
Collecting pickle
Could not find a version that satisfies the requirement pickle (from versions: )
No matching distribution found for pickle
That smells like the pickle file has been created with a different version of Pandas, and your currently installed Pandas doesn't have the pandas.core.indexes module that some of the data in the pickle requires.
Which version of Pandas are you using? Have you tried upgrading?
EDIT: Pandas 0.19.2 does not have that module:
$ pip install pandas==0.23.3
$ python
>>> import pandas.core.indexes as i
>>>
$ pip install pandas==0.19.2
$ python
>>> import pandas.core.indexes as i
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas.core.indexes'
>>>
I would suggest using pandas pickle method to read .pk file.
import _pickle as cPickle
with open('filename.pkl', 'rb') as fo:
dict = cPickle.load(fo, encoding='latin1’)
see doc here. Pickle Read
The answer by #AKX made me realise that it was probably a version problem Pandas. However, I only needed to upgrade.
pip install pandas --upgrade
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn import svm
it gives the following error-
Traceback (most recent call last):
File "/home/songoku/PycharmProjects/untitled/sklearn.py", line 4, in <module>
from sklearn import datasets
File "/home/songoku/PycharmProjects/untitled/sklearn.py", line 4, in <module>
from sklearn import datasets
ImportError: cannot import name 'datasets'
Rename /home/songoku/PycharmProjects/untitled/sklearn.py to something that differs from the SKLearn module name: sklearn.py
Try checking the version of sklearn first. The modules like data-sets and svm is not a part of sklearn packages (0.19 <) i.e less than version number 0.19.0.
You can check this on the command line: pip3 list
it shows you the version of all libraries installed by pip3.
Note: Always double check if you istalled the libraries as a part of anaconda or pip3
Following the tutorial:
http://www.pyimagesearch.com/2016/08/10/imagenet-classification-with-python-and-keras/#comment-419896
Using these files:
https://github.com/fchollet/deep-learning-models
I get 2 separate errors depending on how I execute:
Running in PyCharm:
Using TensorFlow backend.
usage: test_imagenet.py [-h] -i IMAGE
test_imagenet.py: error: the following arguments are required: -i/--image
Running in cmd line:
C:\Users\AppData\Local\Programs\Python\Python35\Scripts>python deep-learning-models/test_imagenet.py --image deep-learning-models/images/dog.jpg
Traceback (most recent call last):
File "deep-learning-models/test_imagenet.py", line 2, in <module>
from keras.preprocessing import image as image_utils
ImportError: No module named keras.preprocessing
How do I resolve?
Its best if you solve this problem outside running the above script... Here is what you can try in your command line environment to make sure it works outside your script:
>>> import keras
Using TensorFlow backend.
>>> keras.__version__
'1.2.1'
>>> keras.preprocessing
<module 'keras.preprocessing' from '/usr/local/lib/python2.7/dist-packages/keras/preprocessing/__init__.pyc'>
>>> from keras.preprocessing import image as image_utils
>>>
Make sure you have latest version of keras installed. If you get above working then it could be the environment issue where above script is not able to find the keras package. However if above does not work or work partially you would need to install keras again by removing it first..
$ pip install keras --user
Every dependency in a python project need to be installed using pip or easy_install or from the source code. You will have to install the keras module as mentioned here.
This happened to me. It turned out I was working in a pyvenv which wasn't activated. Just run source bin/activate on Linux/Mac or Scripts\activate.bat on Windows
from keras.models import Sequential
from keras import legacy_tf_layer
from keras.preprocessing import image as image_utils
from keras.preprcessing.text import Toknizer
import pandas as pd
from sklearn.model_selection import train_test_spli