Reputation: 31
there~
I tried to find the root cause of this issue on my computer here and there, however, I didn't get the right way to fix it. Could you help me?
The following is my situation.
OS : Windows7 Python : Installed by Anaconda3 full package(Python3.5.6)
Whenever I try to import every attributes in the module, I got the error messeges.
import matplotlib as mpl
There was no error messege if I just imported 'matplotlib' as above.
import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<ipython-input-52-a0d2faabd9e9>", line 1, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib.pyplot'
But, when I imported 'matplotlib.pyplot', the messege was as above. It was very weird. The same situation goes on importing 'pandas'.
import pandas as pd
There was also no error messege. However, when I imported 'pandas.read_csv', I got the same error messege.
import pandas as pd
df = pd.read_csv("baby-names.csv")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-6e6b54911d31> in <module>
import pandas as pd
df = pd.read_csv("baby-names.csv")
AttributeError: module 'pandas' has no attribute 'read_csv'
I can't understand my situation.
Check 1) No similar file names.
There are no similar file name in my working directory, such as matplotlib, pandas, python files.
Check 2) sys.path
I'm using Spyder(Python 3.6 in Anaconda3) as an interpreter.
import sys
sys.path
Out[35]:
['',
'd:\\ProgramData\\Anaconda3\\lib\\site-packages\\spyder',
'd:\\ProgramData\\Anaconda3\\python36.zip',
'd:\\ProgramData\\Anaconda3\\DLLs',
'd:\\ProgramData\\Anaconda3\\lib',
'd:\\ProgramData\\Anaconda3',
'd:\\ProgramData\\Anaconda3\\lib\\site-packages',
'd:\\ProgramData\\Anaconda3\\lib\\site-packages\\win32',
'd:\\ProgramData\\Anaconda3\\lib\\site-packages\\win32\\lib',
'd:\\ProgramData\\Anaconda3\\lib\\site-packages\\Pythonwin',
'd:\\ProgramData\\Anaconda3\\lib\\site-packages\\IPython\\extensions',
'C:\\Users\\jungkim\\.ipython']
Check 3) The other interpreters
I reconfirmed the same error in the other interpreters, such as Jupyter notebook, just command line. it was ok to import 'matplotlib' itself.
D:\ProgramData\Anaconda3\Lib\site-packages>python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'matplotlib.pyplot'
>>> import matplotlib as mpl
>>> import pandas as pd
>>> pd.read_csv("baby-names.csv")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'pandas' has no attribute 'read_csv'
Check 4) The package versions
D:\ProgramData\Anaconda3\Scripts>pip list
Package Version
---------------------------------- ---------
....
matplotlib 2.2.2
....
pandas 0.23.0
....
Check 5) Modules path
There seems to be nothing special.
import matplotlib as mpl
mpl.__path__
Out[37]: _NamespacePath(['d:\\ProgramData\\Anaconda3\\lib\\site-packages\\matplotlib'])
import pandas as pd
pd.__path__
Out[39]: _NamespacePath(['d:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas'])
Upvotes: 2
Views: 1974
Reputation: 31
Thanks to all your comments. Anyway, I could get out of the hell when removed all kinds of folders related with the previous Python versions and uninstalled the Anaconda3, re-started the system, reinstalled the Anaconda3. wow~!, Everybody who gave comments to me made me inspire to do it! Thanks guys!
The following are the right Pandas dictionary key lists. I didn't get the lists before removing all kinds of files and folders related with the previous Python versions.
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bi
t (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> pd.__dict__.keys()
dict_keys(['__name__', '__doc__', '__package__', '__loader__', '__spec__', '__pa
th__', '__file__', '__cached__', '__builtins__', '__docformat__', 'compat', 'np'
, '_np_version_under1p10', '_np_version_under1p11', '_np_version_under1p12', '_n
p_version_under1p13', '_np_version_under1p14', '_np_version_under1p15', '_libs',
'_hashtable', '_lib', '_tslib', 'datetime', 'core', 'io', 'pandas', 'errors', '
util', 'tseries', 'plotting', 'factorize', 'unique', 'value_counts', 'isna', 'is
null', 'notna', 'notnull', 'Categorical', 'Grouper', 'set_eng_float_format', 'In
dex', 'CategoricalIndex', 'Int64Index', 'UInt64Index', 'RangeIndex', 'Float64Ind
ex', 'MultiIndex', 'IntervalIndex', 'TimedeltaIndex', 'DatetimeIndex', 'PeriodIn
dex', 'NaT', 'Period', 'period_range', 'pnow', 'Timedelta', 'timedelta_range', '
Timestamp', 'date_range', 'bdate_range', 'Interval', 'interval_range', 'Series',
'DataFrame', 'Panel', 'WidePanel', 'get_dummies', 'IndexSlice', 'to_numeric', '
DateOffset', 'to_datetime', 'to_timedelta', 'datetools', 'get_option', 'set_opti
on', 'reset_option', 'describe_option', 'option_context', 'options', 'match', 'g
roupby', 'TimeGrouper', 'SparseArray', 'SparseSeries', 'SparseDataFrame', 'infer
_freq', 'offsets', 'eval', 'Expr', 'concat', 'melt', 'lreshape', 'wide_to_long',
'pivot', 'merge', 'merge_ordered', 'merge_asof', 'pivot_table', 'crosstab', 'cu
t', 'qcut', 'tools', 'plot_params', 'scatter_matrix', 'show_versions', 'api', 'r
ead_csv', 'read_table', 'read_fwf', 'read_clipboard', 'ExcelFile', 'ExcelWriter'
, 'read_excel', 'HDFStore', 'get_store', 'read_hdf', 'read_json', 'read_html', '
read_sql', 'read_sql_table', 'read_sql_query', 'read_sas', 'read_feather', 'read
_parquet', 'read_stata', 'read_pickle', 'to_pickle', 'read_msgpack', 'to_msgpack
', 'read_gbq', 'Term', 'test', 'testing', '_DeprecatedModule', 'json', 'parser',
'lib', 'tslib', '_version', '__version__'])
>>>
Upvotes: 1