简体   繁体   English

问:ModuleNotFoundError:没有名为“ matplotlib.pyplot”的模块,等等

[英]Q: ModuleNotFoundError: No module named 'matplotlib.pyplot', etc

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) 操作系统:Windows7 Python:由Anaconda3完整软件包安装(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. 如果我像上面那样导入了“ matplotlib”,则不会出现错误消息。

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. 但是,当我导入“ matplotlib.pyplot”时,消息如上所述。 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. 但是,当我导入“ pandas.read_csv”时,我得到了同样的错误信息。

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. 检查1)没有相似的文件名。

There are no similar file name in my working directory, such as matplotlib, pandas, python files. 我的工作目录中没有类似的文件名,例如matplotlib,pandas,python文件。

Check 2) sys.path 检查2)sys.path

I'm using Spyder(Python 3.6 in Anaconda3) as an interpreter. 我正在使用Spyder(Anaconda3中的Python 3.6)作为解释器。

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 检查3)其他口译员

I reconfirmed the same error in the other interpreters, such as Jupyter notebook, just command line. 我在其他解释器中再次确认了相同的错误,例如Jupyter notebook,仅在命令行中。 it was ok to import 'matplotlib' itself. 可以导入'matplotlib'本身。

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 检查4)软件包版本

D:\ProgramData\Anaconda3\Scripts>pip list
Package                            Version
---------------------------------- ---------
....
matplotlib                         2.2.2
....
pandas                             0.23.0
....

Check 5) Modules path 检查5)模块路径

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'])
  1. Is there anyone to suffer from the same situation? 有没有人会遭受同样的情况?
  2. Is there the way to look into the attribute lists in each module(such as Pandas, Numpy, Matplotlib, etc.)? 有没有办法查看每个模块中的属性列表(例如Pandas,Numpy,Matplotlib等)?

Try renaming your baby-names.py to baby_names.py . 尝试将baby-names.py重命名为baby_names.py Pandas may be confused about what to import. 熊猫可能对进口什么感到困惑。

As for the matplotlib.pyplot import, try adding: 至于matplotlib.pyplot导入,请尝试添加:

#!/usr/bin/env python

to the top of your script. 到脚本顶部。 If that does't help it, than restart terminal and run: 如果那没有帮助,那么重新启动终端并运行:

conda install matplotlib

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. 无论如何,当我删除与以前的Python版本相关的各种文件夹并卸载Anaconda3,重新启动系统,重新安装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. 以下是正确的Pandas词典密钥列表。 I didn't get the lists before removing all kinds of files and folders related with the previous Python versions. 在删除与以前的Python版本相关的所有文件和文件夹之前,我没有得到这些列表。

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__'])
>>>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ModuleNotFoundError:没有名为“matplotlib.pyplot”的模块 - ModuleNotFoundError: No module named 'matplotlib.pyplot' 导入错误:没有名为 matplotlib.pyplot 的模块 - ImportError: No module named matplotlib.pyplot 将 matplotlib.pyplot 作为 plt 导入时出现问题(ModuleNotFoundError: No module named 'PIL') - Having problems with importing matplotlib.pyplot as plt (ModuleNotFoundError: No module named 'PIL') 来自matplotlib.pyplot import plt ImportError:没有名为&#39;matplotlib&#39;的模块 - from matplotlib.pyplot import plt ImportError: No module named 'matplotlib' 当我尝试运行“import matplotlib.pyplot as plt”时,我收到以下错误:“ModuleNotFoundError: No module named 'PIL'” - When I try to run “import matplotlib.pyplot as plt”, I receive the following error: “ModuleNotFoundError: No module named 'PIL'” 代码未找到matplotlib.pyplot模块 - Code is not finding the matplotlib.pyplot module 模块“matplotlib.pyplot”没有属性“xaxis” - module 'matplotlib.pyplot' has no attribute 'xaxis' 模块 &#39;matplotlib.pyplot&#39; 没有属性 &#39;patches&#39; - module 'matplotlib.pyplot' has no attribute 'patches' 模块“matplotlib.pyplot”没有属性“yaxis” - module 'matplotlib.pyplot' has no attribute 'yaxis' 当我使用matplotlib.pyplot时,在Python 3.6中没有名为PyQt4的模块 - No module named PyQt4 in python 3.6 when I use matplotlib.pyplot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM