Python 导入错误:安装 matplotlib 时没有名为 pkg_resources 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31438293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 10:00:16  来源:igfitidea点击:

ImportError: No module named pkg_resources on installing matplotlib

pythonmatplotlibcentosinstallpip

提问by nikosd

This is on CentOs 6.6. I am trying to set up a scientific python environment. I want to avoid Anaconda. When trying to install matplotlib, I get "ImportError: No module named pkg_resources". Full install history:

这是在 CentOs 6.6 上。我正在尝试建立一个科学的 python 环境。我想避免使用 Anaconda。尝试安装 matplotlib 时,出现“ImportError: No module named pkg_resources”。完整的安装历史:

sudo yum install gcc-c++.x86_64
sudo yum install gcc
sudo yum install atlas atlas-devel lapack-devel blas-devel
sudo yum install python-devel
sudo pip install numpy
sudo pip install scipy
sudo pip install pandas
sudo pip install matplotlib

At the last step, I get the message

在最后一步,我收到消息

Complete output from command python setup.py egg_info:
The required version of distribute (>=0.6.28) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U distribute'.

Then I do

然后我做

sudo pip install --upgrade distribute

which installs distribute-0.7.3, setuptools-18.0.1. Then:

安装distribute-0.7.3, setuptools-18.0.1. 然后:

sudo pip install matplotlib

which results in:

这导致:

File "/usr/bin/pip", line 5, in <module>
  from pkg_resources import load_entry_point
ImportError: No module named pkg_resources

Any ideas?

有任何想法吗?

Update

更新

After the above steps, setuptoolsand pipare broken in this installation. From a python shell, doing help()followed by modulesdoes not list setuptools. A search in the filesystem for setuptoolsdirectories reveals:

经过以上步骤,setuptoolspip在此安装打破。在 python shell 中,执行help()后跟modules不列出setuptools. 在文件系统中搜索setuptools目录显示:

/usr/lib/python2.6/site-packages/setuptools-18.0.1.dist-info/

while the setuptools.pthfile in /usr/lib/python2.6/site-packages/contains a pointer to the non-existent ./setuptools-0.6c11-py2.6.egg-info.

setuptools.pth文件 in/usr/lib/python2.6/site-packages/包含一个指向不存在的./setuptools-0.6c11-py2.6.egg-info.

At the same time, there is a directory

同时,还有一个目录

/usr/share/doc/python-setuptools-0.6.10/

After all this, pip no longer works.

毕竟,pip不再有效。

回答by Pavan Kumar N

Try this for OS supporting apt-get (Ubuntu etc)

试试这个支持 apt-get 的操作系统(Ubuntu 等)

sudo apt-get install python-pkg-resources python-setuptools --reinstall

sudo apt-get install python-pkg-resources python-setuptools --reinstall

回答by user41734

@pavan they said CentOS, so apt is unlikely to help them.

@pavan 他们说 CentOS,所以 apt 不太可能帮助他们。

They could, though, do :

不过,他们可以:

yum remove python-setuptools

yum install python-setuptools  

(my also need to reinstall pip: yum install python-pip )

(我还需要重新安装 pip: yum install python-pip )

And that might fix the problem.

这可能会解决问题。

回答by user6868762

Try install python-pip (and dependencies):

尝试安装 python-pip(和依赖项):

yum install python-pip

This solved my problem (Centos release 6.8).

这解决了我的问题(Centos 6.8 版)。