4

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'
saurabh
  • 83
  • 1
  • 7
  • If you are using the latest 2.7 version, a quick workaround should be using `python -m ensurepip`. – cel Dec 24 '14 at 10:24
  • What about directly invoking python2.7, ie: `python2.7 get-pip.py` – user590028 Dec 24 '14 at 10:29
  • Can you elaborate, why you are using `--no-setuptools`? This suppresses the installation of `setuptools` and `pip`. That's fair enough, but why then are you trying to bootstrap `pip` afterwards? – cel Dec 24 '14 at 10:44
  • @cel I had tried without --no-setuptools initially but then this same error popped up while creating the virtualenv. I've edited the question with the relevant output. – saurabh Dec 24 '14 at 10:51
  • @user590028 Tried that also but it doesn't work. See the edit in the question. – saurabh Dec 24 '14 at 10:58
  • @saurabh, I cannot reproduce this issue. I would try updating `pip` and `virtualenv` to the latest versions and try again. If this doesn't help, you can still install `python 2.7.9` and use `python -m ensurepip` to bootstrap your `pip`. This does not depend on a parent interpreter and should even work if your `python2.6` should be borked somehow. – cel Dec 24 '14 at 12:51
  • @cel I uninstalled pip and tried installing it again using `python2.7 get-pip.py` but ended up with the same error. This was with 2.7.8 though. Using `python2.6 get-pip.py` works fine. I installed python2.7.9 and tried `python2.7 get-pip.py` which again throws the same error. Tried `python2.7 -m ensurepip` but that gives me a `Ignoring ensurepip failure: pip 1.5.6 requires SSL/TLS` message. Anything I'm missing? – saurabh Dec 24 '14 at 14:56
  • @saurabh weird - google suggests that installing `openssl` could fix this problem. – cel Dec 24 '14 at 15:05

1 Answers1

9

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!

Fernando Echeverria
  • 7,706
  • 4
  • 17
  • 13
  • Yes. My problem was exactly the same as yours. I ignored the make summary and went ahead with the install. Although I finally ended up installing python 2.7.9 as suggested by cel in the comments above, I'm pretty sure I would've got 2.7.8 working as well once I had the ssl libraries installed. Anyway, marking your answer as the correct solution to the problem. – saurabh Jan 15 '15 at 22:00
  • For osx users, the way to handle this would be through homebrew, and the simple answer is... `brew install openssl`, then `brew unlink python`, then `brew install python`. It just worked for me. – bwest87 Mar 14 '15 at 01:06