Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError while installing pip in virtualenv

I have a rhel machine with python2.6 installed on it. I've been trying to have an alternate install of python2.7 and set up a virtualenv for using 2.7. I installed python2.7 by building from source as follows:

./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib" 
make && make altinstall

I already had virtualenv installed on the system so I used it to create a venv for 2.7 as follows:

virtualenv -p python2.7 --no-setuptools py27
. py27/bin/activate

Now when I try to install pip inside the venv, it fails like so:

python get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 19857, in <module>
  main()
File "get-pip.py", line 151, in main
  bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 81, in bootstrap
  import pip
File "/tmp/tmpArPs31/pip.zip/pip/__init__.py", line 15, in <module>
File "/tmp/tmpArPs31/pip.zip/pip/vcs/mercurial.py", line 11, in <module>
File "/tmp/tmpArPs31/pip.zip/pip/download.py", line 29, in <module>
File "/tmp/tmpArPs31/pip.zip/pip/_vendor/__init__.py", line 81, in load_module
ImportError: No module named 'pip._vendor.requests'

Can't figure out what's going wrong here. Please help.

I've installed python 2.7.8.

EDIT: I initially tried creating virtualenv without --no-setuptools option but that gave me the same error:

virtualenv -p python2.7 py27_with_pip
Running virtualenv with interpreter /usr/local/bin/python2.7
New python executable in py27_with_pip/bin/python2.7
Also creating executable in py27_with_pip/bin/python
Installing setuptools, pip...
  Complete output from command /data1/home/sagraw1/...th_pip/bin/python2.7 -c "import sys, pip;     sys...d\"] + sys.argv[1:]))" setuptools pip:
  Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv_support/pip-6.0-    py2.py3-none-any.whl/pip/__init__.py", line 15, in <module>
  File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv_support/pip-6.0-py2.py3-none-any.whl/pip/vcs/mercurial.py", line 11, in <module>
  File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv_support/pip-6.0-py2.py3-none-any.whl/pip/download.py", line 29, in <module>
  File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv_support/pip-6.0-py2.py3-none-any.whl/pip/_vendor/__init__.py", line 81, in load_module
ImportError: No module named 'pip._vendor.requests'
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv.py", line 2363, in <module>
    main()
  File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv.py", line 848, in main
symlink=options.symlink)
  File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv.py", line 1016, in create_environment
    install_wheel(to_install, py_executable, search_dirs)
  File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv.py", line 984, in install_wheel
    'PIP_NO_INDEX': '1'
  File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv.py", line 926, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /data1/home/sagraw1/...th_pip/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 1

I tried installing pip with python2.7 directly but even that doesn't work:

python2.7 get-pip.py
Traceback (most recent call last):
  File "get-pip.py", line 19857, in <module>
    main()
  File "get-pip.py", line 151, in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py", line 81, in bootstrap
    import pip
  File "/tmp/tmpPSVEkk/pip.zip/pip/__init__.py", line 15, in <module>
  File "/tmp/tmpPSVEkk/pip.zip/pip/vcs/mercurial.py", line 11, in <module>
  File "/tmp/tmpPSVEkk/pip.zip/pip/download.py", line 29, in <module>
  File "/tmp/tmpPSVEkk/pip.zip/pip/_vendor/__init__.py", line 81, in load_module
ImportError: No module named 'pip._vendor.requests'
like image 753
saurabh Avatar asked Jan 09 '23 05:01

saurabh


1 Answers

I was in a situation similar to yours, and I eventually found the fix. At least in my case the root problem was that when I compiled python 2.7.8 the build process didn't find the proper OpenSSL libraries (because they were not installed on my system). After make finished running it showed a summary similar to this:

Failed to find the necessary bits to build these modules:
_bsddb             _curses            _curses_panel
_hashlib           _sqlite3           _ssl

This doesn't prevent make install from working, and after that Python works just fine, except that it can't access https URLs and other related functionality. You can tell if this is your case by starting python and then typing

import ssl

If you see an ImportError, then the ssl module is missing. Otherwise, you see no message at all.

I fixed this by installing the OpenSSL libraries by running (as root):

yum install openssl-devel

After this was in place, I rebuilt Python with make (now _ssl was not listed as missing), followed by make install. After this, running get-pip.py worked without a hitch. Hope this helps!

like image 84
Fernando Echeverria Avatar answered Jan 15 '23 14:01

Fernando Echeverria