Python 为什么matplotlib无法将matplotlib.pyplot导入为plt
我使用Python 为什么matplotlib无法将matplotlib.pyplot导入为plt,python,ubuntu,matplotlib,importerror,Python,Ubuntu,Matplotlib,Importerror,我使用conda安装了matplotlib: conda install matplotlib 以下代码失败: #!/usr/bin/env python import matplotlib import matplotlib.pyplot as plt 出现此错误消息时: “ImportError:没有名为'matplotlib.pyplot'的模块” 我尝试使用apt get安装matplotlib: sudo apt-get install python3-matplotlib 我
conda
安装了matplotlib:
conda install matplotlib
以下代码失败:
#!/usr/bin/env python
import matplotlib
import matplotlib.pyplot as plt
出现此错误消息时:
“ImportError:没有名为'matplotlib.pyplot'的模块”
我尝试使用apt get安装matplotlib
:
sudo apt-get install python3-matplotlib
我也犯了同样的错误
我试着用ubuntu应用程序加载matplotlib,但得到了相同的错误
我尝试从GitHub克隆,方法是:
git clone git://github.com/matplotlib/matplotlib.git
我也犯了同样的错误
我查看了matplotlib目录,没有看到pyplot.py条目。我确实在matplotlib/lib/matplotlib中找到了pyplot.py。我把它复制到matplotlib。错误消失了,但我得到了pyplot试图包含的另一个模块。我在matplotlib/lib/matplotlib中找到了它。我把它复制到matplotlib。获取另一个模块的另一个错误。抄袭了它。最后,我得到了一个模块的错误,我找不到
我不知道下一步要尝试什么。通常情况下,
conda
不会添加到您的路径中(它会在安装过程中询问您是否应该这样做,但默认为“否”),因此默认的python
将是系统python 2(您使用python 3
启动python 3)
您可以通过以下方式进行验证:
$ which python
这将返回与python
命令关联的路径。这可能会返回到SystemsPython2“安装”的路径
例如,在我的Ubuntu机器上,命令which python
和which python3
返回:
usr/bin/python (starts Python 2.7.12)
usr/bin/python3 (starts Python 3.5.2)
而我的conda安装在/home/michael/miniconda
目录的某个地方
有几个选项可以选择如何使用conda
Python:
- 将conda目录临时添加到路径中。(参见示例)
- 将conda目录永久添加到路径。(参见示例)
- 使用
,它会为您提供一个终端,该终端的路径前面有conda目录anaconda promt