[英]Install matplotlib module in python
I am trying to install matplotlib in python. 我正在尝试在python中安装matplotlib。 But getting
ModuleNotFoundError
. 但是获取
ModuleNotFoundError
。
I tried installing matplotlib in the linux command prompt with 我尝试使用以下命令在linux命令提示符中安装matplotlib
sudo pip install matplotlib
I got the message: 我收到消息:
Successfully installed matplotlib-2.2.4
成功安装matplotlib-2.2.4
But I could not find the package in Linux. 但是我在Linux中找不到该软件包。
Also when I try to import it in Python I am getting 当我尝试将其导入Python时
import matplotlib
ModuleNotFoundError: No module named 'matplotlib'
I expect matplotlib to be installed but I have the error 我希望安装matplotlib,但出现错误
ModuleNotFoundError: No Module named 'matplotlib'
ModuleNotFoundError:没有名为“ matplotlib”的模块
$ sudo pip install matplotlib
$ sudo pip安装matplotlib
You may as well $ sudo pip uninstall matplotlib
since that's not doing you any good. 您也可以
$ sudo pip uninstall matplotlib
因为这对您没有任何好处。
Using sudo
changes your environment. 使用
sudo
改变您的环境。 In particular it may change $PATH
and hence change the output of $ which python
, which matters for your import
. 特别是它可能会更改
$PATH
并因此更改$ which python
的输出,这对您的import
。 The env var PYTHONPATH
can also be relevant, as it affects sys.path
. env var
PYTHONPATH
也可能是相关的,因为它影响sys.path
。
Verify that $ which python
and $ python --version
return what you expect. 验证
$ which python
和$ python --version
返回您期望的结果。
Issue these commands: 发出以下命令:
$ python -m pip install matplotlib
$ python -c 'import matplotlib'
Expected output is that the import
silently succeeds. 预期的输出是
import
提示成功。
If you continue to have trouble, inspect the path
variable and ls -l
the directories it mentions: 如果仍然遇到问题,请检查
path
变量,并在ls -l
所提到的目录中进行检查:
$ python
>>> import pprint, sys
>>> pprint.pprint(sys.path)
Consider using conda to manage your library dependencies. 考虑使用conda来管理您的库依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.