简体   繁体   English

导入错误:没有名为 sysconfig 的模块——无法让 pip 工作

[英]ImportError: No module named sysconfig--can't get pip working

I'm really struggling with pip on a RedHat 6.9 system.我真的在 RedHat 6.9 系统上与 pip 苦苦挣扎。 Every time I tried to use pip, I got每次我尝试使用 pip 时,我都会得到

ImportError: No module named sysconfig

I tried Googling for solutions.我尝试谷歌搜索解决方案。 I don't have apt-get and can't seem to get it with yum, so purging setuptools was out of the question.我没有 apt-get 并且似乎无法通过 yum 获得它,因此清除 setuptools 是不可能的。 I did my best to delete setuptools by hand so I could reinstall them, but yum is convinced there are still setuptools on the machine.我尽力手动删除 setuptools 以便我可以重新安装它们,但是 yum 确信机器上仍然有 setuptools。

Pretty much any of the advice involving downloading something with yum doesn't work for me.几乎所有涉及使用 yum 下载内容的建议对我都不起作用。 Yum always says it can't find what I'm looking for.百胜总是说找不到我要找的东西。 So if there's a way I can download something without yum or apt-get (for example, not through the terminal), that would probably be best.因此,如果有一种方法可以在没有 yum 或 apt-get 的情况下下载某些内容(例如,不通过终端),那可能是最好的。

I have both Python 3 and Python 2 on my machine, so I don't know if that will change the advice that you guys can give me.我的机器上有 Python 3 和 Python 2,所以我不知道这是否会改变你们给我的建议。

1000 thanks to anyone who can help! 1000 感谢任何可以提供帮助的人! Right now I can only get things done through anaconda interfaces (such as Jupyter notebooks and Spyder) which is really limiting.现在我只能通过 anaconda 接口(例如 Jupyter notebooks 和 Spyder)来完成工作,这真的很有限。

EDIT: Here is my error trace:编辑:这是我的错误跟踪:

Traceback (most recent call last):

  File "/usr/bin/pip2", line 5, in <module>

    from pkg_resources import load_entry_point

  File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 947, in <module>

    class Environment(object):

  File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 951, in Environment

    self, search_path=None, platform=get_supported_platform(),

  File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 180, in get_supported_platform

    plat = get_build_platform()

  File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 380, in get_build_platform

    from sysconfig import get_platform

ImportError: No module named sysconfig

EDIT 2: @hoefling requested that I post the output of the following commands;编辑 2: @hoefling 要求我发布以下命令的输出; first:第一的:

$ yum list installed | grep setuptools
*Note* Red Hat Network repositories are not listed below. You must run this command as root to access RHN repositories.
python-setuptools.noarch     0.6.10-4.el6_9      @ncep-base-x86_64-workstation-6

and:和:

$ grep ^Version: /usr/lib/python2.6/site-packages/setuptools-*.egg-info/PKG-INFO
grep: /usr/lib/python2.6/site-packages/setuptools-*.egg-info/PKG-INFO: No such file or directory

I've got the same error with python2.6 on redHat server 6.9 :我在 redHat 服务器 6.9 上使用 python2.6 遇到了同样的错误:

pip version
Traceback (most recent call last):
  File "/usr/bin/pip", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 947, in <module>
    class Environment(object):
  File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 951, in Environment
    self, search_path=None, platform=get_supported_platform(),
  File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 180, in get_supported_platform
    plat = get_build_platform()
  File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 380, in get_build_platform
    from sysconfig import get_platform
ImportError: No module named sysconfig

I removed :我删除了 :

rm /usr/lib/python2.6/site-packages/pkg_resources*

and i reinstalled python-setuptools我重新安装了 python-setuptools

yum reinstall python-setuptools

After this fix :修复后:

pip --version
pip 7.1.0 from /usr/lib/python2.6/site-packages (python 2.6)

Try with试试

python3 -m ensurepip --default-pip

then do然后做

pip3 install [package]

this will instruct python to use pip3这将指示 python 使用 pip3

I had the exact same problem on Cent6.9 and the instructions here didn't quite fix the problem.我在 Cent6.9 上遇到了完全相同的问题,这里的说明并没有完全解决问题。 The fix the same issue, I needed to backup my entire /usr/lib/python2.6/ folder, and copy them to a new folder with only the modules yum, urlgrabber, and rpmUtils (otherwise yum will break).修复同样的问题,我需要备份我的整个 /usr/lib/python2.6/ 文件夹,并将它们复制到一个只有 yum、urlgrabber 和 rpmUtils 模块的新文件夹中(否则 yum 会中断)。

Keep in mind that this fix can seriously break your system (either by breaking yum, or by removing in-use python modules).请记住,此修复程序可能会严重破坏您的系统(通过破坏 yum 或删除正在使用的 Python 模块)。 This will uninstall every single python module.这将卸载每个 python 模块。 This will also uninstall python34!这也将卸载python34!

cd /usr/lib/
cp -a python2.6 python2.6-bak
cd /usr/lib/python2.6
rm -rf ./* #ow
cp -a /usr/lib/python2.6-bak/site-packages/yum /usr/lib/python2.6/
cp -a /usr/lib/python2.6-bak/site-packages/urlgrabber /usr/lib/python2.6/
cp -a /usr/lib/python2.6-bak/site-packages/rpmUtils /usr/lib/python2.6/
rpm -qa | grep python34 | xargs yum -y erase
rpm -qa | grep python | xargs yum -y reinstall
yum -y reinstall python-setuptools python2-setuptools python-pip

From here :这里

When I ran into this, it was caused by having /usr/lib/python2.6/site-packages/pkg_resources/ conflicting with /usr/lib/python2.6/site-packages/pkg_resources.py.当我遇到这个时,它是由 /usr/lib/python2.6/site-packages/pkg_resources/ 与 /usr/lib/python2.6/site-packages/pkg_resources.py 冲突引起的。 Erasing the directory allowed everything to work as before.擦除目录允许一切像以前一样工作。 I assume a pip install was the cause, but don't know which package.我认为 pip install 是原因,但不知道是哪个包。

Helped me too - rm -rf /usr/lib/python2.6/site-packages/pkg_resources ( use at your own risk ! ).也帮助了我 - rm -rf /usr/lib/python2.6/site-packages/pkg_resources使用风险自负! )。

Try this尝试这个

Remove completely python-setuptools and delete the folder from /usr/lib/python2.6/site-packages/ .完全删除python-setuptools并从/usr/lib/python2.6/site-packages/删除文件夹。

then remove manually from the site-packages folder the module: pyOpenSSL it was after trying to upgrade it that everything went south.然后从site-packages文件夹中手动删除模块: pyOpenSSL在尝试升级它之后,一切都向南了。

rm -rf pyOpenSSL-18.0.0-py2.6.egg/

install back from sudo python-setuptools now pip list can list the modules and no more errors with easy_install either.从 sudo python-setuptools安装回现在pip list可以列出模块,并且使用easy_install也不会再出现错误。

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

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