简体   繁体   English

Mac中的matplotlib导入错误

[英]matplotlib import error in Mac

System: OX E Python source: python.org 系统:OX E Python来源:python.org

I used pip to install matplotlib and here is the result I got 我使用pip安装matplotlib,这是我得到的结果

sudo pip install matplotlib

The directory '/Users/clarence/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. 目录“ / Users / clarence / Library / Caches / pip / http”或其父目录不属于当前用户,并且缓存已被禁用。 Please check the permissions and owner of that directory. 请检查该目录的权限和所有者。 If executing pip with sudo, you may want sudo's -H flag. 如果使用sudo执行pip,则可能需要sudo的-H标志。 The directory '/Users/clarence/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. 目录“ / Users / clarence / Library / Caches / pip”或其父目录不属于当前用户,并且缓存轮已被禁用。 check the permissions and owner of that directory. 检查该目录的权限和所有者。 If executing pip with sudo, you may want sudo's -H flag. 如果使用sudo执行pip,则可能需要sudo的-H标志。 Requirement already satisfied (use --upgrade to upgrade): matplotlib in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python Requirement already satisfied (use --upgrade to upgrade): numpy>=1.5 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib) Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib) Requirement already satisfied (use --upgrade to upgrade): tornado in /Library/Python/2.7/site-packages (from matplotlib) Requirement already satisfied (use --upgrade to upgrade): pyparsing>=1.5.6 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib) Requirement already satisfied (use --upgrade to upgrade): nose in /Library/Python/2.7/site-packages (from matplotlib) Requirement already satisfied (use --upgrade to upgrade): certifi in /Library/Python/2.7/site-packages (from 需求已满足(使用--upgrade升级):/ System / Library / Frameworks / Python.matwork / Versions / 2.7 / Extras / lib / python中的matplotlib需求已满足(使用--upgrade升级):numpy> = 1.5在/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python中(来自matplotlib)已满足要求(使用--upgrade进行升级):/ System / Library / Frameworks / Python中的python-dateutil。 framework / Versions / 2.7 / Extras / lib / python(来自matplotlib)已满足要求(使用--upgrade进行升级):/Library/Python/2.7/site-packages中的龙卷风(来自matplotlib)已满足要求(使用- (升级至升级):pyparsing> = 1.5.6 /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python(来自matplotlib)已满足要求(使用--upgrade进行升级): /library/Python/2.7/site-packages(来自matplotlib)已满足要求(使用--upgrade升级):/Library/Python/2.7/site-packages中的证书(来自 tornado->matplotlib) Requirement already satisfied (use --upgrade to upgrade): backports-abc>=0.4 in /Library/Python/2.7/site-packages (from tornado->matplotlib) Requirement already satisfied (use --upgrade to upgrade): backports.ssl-match-hostname in /Library/Python/2.7/site-packages (from tornado->matplotlib) Requirement already satisfied (use --upgrade to upgrade): singledispatch in /Library/Python/2.7/site-packages (from tornado->matplotlib) Requirement already satisfied (use --upgrade to upgrade): six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from singledispatch->tornado->matplotlib) Clarences-MacBook-Pro:~ clarence$ sudo -H pip install matplotlib Requirement already satisfied (use --upgrade to upgrade): matplotlib in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python Requirement already satisfied (use --upgrade to upgrade): numpy>=1.5 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from m tornado-> matplotlib)满足要求(使用--upgrade升级):/Library/Python/2.7/site-packages中的backports-abc> = 0.4(来自tornado-> matplotlib)满足要求(使用--upgrade至升级):/Library/Python/2.7/site-packages中的backports.ssl-match-hostname(来自tornado-> matplotlib)满足要求(使用--upgrade升级):/Library/Python/2.7/site中的单个调度-packages(来自tornado-> matplotlib)已满足要求(使用--upgrade升级):/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python中有六个(来自singledispatch-> tornado- > matplotlib)Clarences-MacBook-Pro:〜clarence $ sudo -H pip install matplotlib要求已经满足(使用--upgrade升级):/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib中的matplotlib / python要求已经满足(使用--upgrade升级):/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python中的numpy> = 1.5(来自m atplotlib) Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib) Requirement already satisfied (use --upgrade to upgrade): tornado in /Library/Python/2.7/site-packages (from matplotlib) Requirement already satisfied (use --upgrade to upgrade): pyparsing>=1.5.6 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib) Requirement already satisfied (use --upgrade to upgrade): nose in /Library/Python/2.7/site-packages (from matplotlib) Requirement already satisfied (use --upgrade to upgrade): certifi in /Library/Python/2.7/site-packages (from tornado->matplotlib) Requirement already satisfied (use --upgrade to upgrade): backports-abc>=0.4 in /Library/Python/2.7/site-packages (from tornado->matplotlib) Requirement already satisfied (use --upgrade to upgrade): backports.ssl-match-hostname in /Library/Python/2.7/site-packages (from tornado- atplotlib)需求已满足(使用--upgrade进行升级):/ System / Library / Frameworks / Python.framework / Versions / 2.7 / Extras / lib / python中的python-dateutil(来自matplotlib)需求已满足(使用--upgrade升级):/ Library / Python / 2.7 / site-packages中的龙卷风(来自matplotlib)要求已得到满足(使用--upgrade进行升级):/System/Library/Frameworks/Python.framework/中的pyparsing> = 1.5.6版本/2.7/Extras/lib/python(来自matplotlib)已满足要求(使用--upgrade进行升级):/Library/Python/2.7/site-packages中的鼻子(来自matplotlib)已满足要求(使用--upgrade至升级):在/Library/Python/2.7/site-packages中认证(来自tornado-> matplotlib)要求已经满足(使用--upgrade升级):backports-abc> = 0.4在/Library/Python/2.7/site-packages中软件包(来自tornado-> matplotlib)已满足要求(使用--upgrade进行升级):/Library/Python/2.7/site-packages中的backports.ssl-match-hostname(来自tornado- >matplotlib) Requirement already satisfied (use --upgrade to upgrade): singledispatch in /Library/Python/2.7/site-packages (from tornado->matplotlib) Requirement already satisfied (use --upgrade to upgrade): six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from singledispatch->tornado->matplotlib) > matplotlib)满足要求(使用--upgrade升级):/Library/Python/2.7/site-packages中的单个分发(来自tornado-> matplotlib)满足要求(使用--upgrade升级):/ System中的六个/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python(来自singledispatch-> tornado-> matplotlib)

When I go ahead the import that library in python. 当我继续使用python导入该库时。 python says it could not find the modulus. python表示找不到模数。

python3.5 -c 'import matplotlib; print(matplotlib.__version__, matplotlib.__file__)'

Traceback (most recent call last): File "", line 1, in ImportError: No module named 'matplotlib' 追溯(最近一次调用):文件“”,ImportError中的第1行:没有名为'matplotlib'的模块

How can I fix this? 我怎样才能解决这个问题?

You need to install those libraries for the same version of python that you are using later to execute your code. 您需要为以后要用于执行代码的相同版本的python安装这些库。

So if you want to use Python 2.7 you have to call 因此,如果您想使用Python 2.7,则必须调用

sudo pip2 install matplotlib

When using python 3.5 use it in a similar way 使用python 3.5时,以类似的方式使用它

sudo pip3 install matplotlib

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM