7

I'm really struggling with pip on a RedHat 6.9 system. Every time I tried to use pip, I got

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. 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.

Pretty much any of the advice involving downloading something with yum doesn't work for me. 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.

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.

1000 thanks to anyone who can help! Right now I can only get things done through anaconda interfaces (such as Jupyter notebooks and Spyder) which is really limiting.

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; 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
12
  • 2
    Most probably pip points to python2.6, if you enter pip -V, where does the location path point to? If this is true - what is your setuptools version for python2.6? Run python2.6 -c "import setuptools; print(setuptools.__version__)" to check that. Most probably you have updated setuptools beyond version 37 that dropped support for Python 2.6.
    – hoefling
    Jun 7, 2018 at 15:33
  • 1
    Also, you don't have setuptools but pip still imports that from somewhere - can you post the complete error trace?
    – hoefling
    Jun 7, 2018 at 16:49
  • 1
    Can you post the output of yum list installed | grep setuptools and grep ^Version: /usr/lib/python2.6/site-packages/setuptools-*.egg-info/PKG-INFO?
    – hoefling
    Jun 8, 2018 at 12:33
  • 6
    Ok, so setuptools should be installed now - can you confirm you have the pkg_resources.py module? Run ls /usr/lib/python2.6/site-packages/pkg_resources.py; echo $?, if this command outputs 0, remove the pkg_resources package: sudo rm -rf /usr/lib/python2.6/site-packages/pkg_resources/. Remove the dir only when the pkg_resources module is found! After that, pip should work again: run smth like pip list to check that.
    – hoefling
    Jun 8, 2018 at 14:06
  • 1
    Nice, glad I could help!
    – hoefling
    Jun 8, 2018 at 16:37

5 Answers 5

10

I've got the same error with python2.6 on redHat server 6.9 :

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

yum reinstall python-setuptools

After this fix :

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

Try with

python3 -m ensurepip --default-pip

then do

pip3 install [package]

this will instruct python to use pip3

0

I had the exact same problem on Cent6.9 and the instructions here didn't quite fix the problem. 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).

Keep in mind that this fix can seriously break your system (either by breaking yum, or by removing in-use python modules). This will uninstall every single python module. This will also uninstall 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
0

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. Erasing the directory allowed everything to work as before. I assume a pip install was the cause, but don't know which package.

Helped me too - rm -rf /usr/lib/python2.6/site-packages/pkg_resources (use at your own risk !).

0

Try this

Remove completely python-setuptools and delete the folder from /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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.