Virtualenv fails on OS X Yosemite with OSError - python

I recently updated to OSX Yosemite, and now I can't use virtualenv / pip.
Whenever I execute:
virtualenv env
It throws a:
OSError: Command /Users/administrator...ux/env/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 1
And within that stack trace pip throws:
ImportError: cannot import name HTTPSHandle
Has anyone else encountered this error? These questions suggest updating homebrew to solve the issue. Which I've done but the issue still persists.
ImportError: cannot import name HTTPSHandler using PIP
ImportError: cannot import name HTTPSHandler installing get-pip.py
ImportError: cannot import name HTTPSHandler using Brew
Full Stack Trace:
Administrators-MacBook-Air :: ~/dev/KaggleAux ‹master› » virtualenv env 127 ↵
New python executable in env/bin/python2.7
Also creating executable in env/bin/python
Installing setuptools, pip...
Complete output from command /Users/administrator...ux/env/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/local/lib/python2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/__init__.py", line 10, in <module>
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/util.py", line 18, in <module>
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/_vendor/distlib/version.py", line 14, in <module>
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/_vendor/distlib/compat.py", line 31, in <module>
ImportError: cannot import name HTTPSHandler
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 824, in main
symlink=options.symlink)
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 992, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 960, in install_wheel
'PIP_NO_INDEX': '1'
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 902, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /Users/administrator...ux/env/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 1

Solved with:
brew uninstall python
brew install python
pip install --upgrade pip
*Note: You'll also need to a do a fresh pip install for any current projects you're working on.

Related

Virtualenv failing when creating an enviroment

I don't know the reason, but the function mkvirtualenv is ending in the following error:
LEP:~ lep$ mkvirtualenv myenvironment
New python executable in myenvironment/bin/python
Installing setuptools, pip, wheel...
Complete output from command /Users/lep/.virtuale...vironment /bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/lep/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-7.1.0-py2.py3-none-any.whl/pip/__init__.py", line 13, in <module>
File "/Users/lep/anaconda/lib/python2.7/site-packages/virtualenv_support/pip-7.1.0-py2.py3-none-any.whl/pip/utils/__init__.py", line 15, in <module>
File "/Users/lep/anaconda/lib/python2.7/zipfile.py", line 6, in <module>
import io
File "/Users/lep/anaconda/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/Users/lep/.virtualenvs/myenvironment/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyErr_ReplaceException
Referenced from: /Users/lep/.virtualenvs/myenvironment/lib/python2.7/lib-dynload/_io.so
Expected in: dynamic lookup
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
File "/Users/lep/anaconda/bin/virtualenv", line 11, in <module>
sys.exit(main())
File "/Users/lep/anaconda/lib/python2.7/site-packages/virtualenv.py", line 832, in main
symlink=options.symlink)
File "/Users/lep/anaconda/lib/python2.7/site-packages/virtualenv.py", line 1004, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "/Users/lep/anaconda/lib/python2.7/site-packages/virtualenv.py", line 969, in install_wheel
'PIP_NO_INDEX': '1'
File "/Users/lep/anaconda/lib/python2.7/site-packages/virtualenv.py", line 910, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /Users/lep/.virtuale...vironment/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel failed with error code 1
It is was working before and now I am getting this error. Does someone can help me?
Thanks in advance,
Rhenan
Looks like you are using Anaconda Python. You should be using Conda to do this not virtenv.
Try:
LEP:~ lep$ conda create --name myenvironment
Try downgrading to python version 2.7.9
conda install python=2.7.9
Kudos to folks here in the GitHub conda issues section
Addendum: Thanks, Josh Trii Johnston for his comment which basically said the same thing I did... I didn't see that before.

AttributeError when running pip in virtualenv

I recently upgraded python from 2.7.6 to 2.7.9 using homebrew. I then tried to 'revirtualise' an existing virtual environment:
sudo virtualenv -p python2.7 existingvenv
But am getting this error:
Traceback (most recent call last):
File "venv.../bin/pip", line 7, in <module>
from pip import main
File "venv.../lib/python2.7/site-packages/pip/__init__.py", line 9, in <module>
from pip.log import logger
File "venv.../lib/python2.7/site-packages/pip/log.py", line 8, in <module>
from pip import backwardcompat
File "venv.../lib/python2.7/site-packages/pip/backwardcompat/__init__.py", line 66, in <module>
from urllib2 import URLError, HTTPError
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 93, in <module>
import hashlib
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 138, in <module>
_hashlib.openssl_md_meth_names)
AttributeError: 'module' object has no attribute 'openssl_md_meth_names'
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 2352, in <module>
main()
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 825, in main
symlink=options.symlink)
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 993, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 961, in install_wheel
'PIP_NO_INDEX': '1'
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 903, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /Users/robertelliott...hflow-app/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 1
I also get the above error when running any pip install x inside the above active virtual environment.
I don't get the error when creating a new virtualenv:
$ virtualenv -p python2.7 newvenv
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
New python executable in newenv/bin/python
Installing setuptools, pip...done.
Is there an old symlink or something inside the existing virtualenv causing the issue and how can I resolve this?
This is because of a new feature in Python, which wheel 0.24 is not compatible with. You'll find a folder called virtualenv_support containing base install files for setuptools, pip, and wheel under your Python 2.7 system install. There are a few solutions. The easiest is to just remove wheel-0.24* from the virtualenv_support folder. If you want to go a step farther, you could download version 0.26 of the wheel .whl file and replace it.
did you try:
sudo virtualenv --clear -p python2.7 existingvenv
?

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'
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!

Error while making virtualenv with python3 interpeter on Mac OS 10.9

Mac OS X Version - 10.9.3
Pip version - pip 1.5.6 from /Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg (python 2.7)
Hello!
When I try to make a virtualenv with python3 interpeter I get this error:
air$ virtualenv python3.4 --python=/usr/local/bin/python3.4
Running virtualenv with interpreter /usr/local/bin/python3.4
Using base prefix '/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4'
New python executable in python3.4/bin/python3.4
Not overwriting existing python script python3.4/bin/python (you must use python3.4/bin/python3.4)
Installing setuptools, pip...
Complete output from command /Users/***/.virt...hon3.4/bin/python3.4 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Library/Python/2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/__init__.py", line 10, in <module>
File "/Library/Python/2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/util.py", line 18, in <module>
File "/Library/Python/2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/_vendor/distlib/version.py", line 14, in <module>
File "/Library/Python/2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/_vendor/distlib/compat.py", line 66, in <module>
ImportError: cannot import name 'HTTPSHandler'
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/virtualenv.py", line 2338, in <module>
main()
File "/Library/Python/2.7/site-packages/virtualenv.py", line 824, in main
symlink=options.symlink)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 992, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 960, in install_wheel
'PIP_NO_INDEX': '1'
File "/Library/Python/2.7/site-packages/virtualenv.py", line 902, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /Users/***/.virt...hon3.4/bin/python3.4 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 1
Binaries:
air$ which python python3 pip openssl virtualenv
/usr/bin/python
/usr/local/bin/python3
/usr/local/bin/pip
/usr/bin/openssl
/usr/local/bin/virtualenv
Python3 was installed with brew install python3
Pip was installed with sudo easy_install pip
PATH:
air$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Please, help me, what i do wrong?
I found this related to my question, but how can i fix it on Mac OS?
UPD:
More info about system:
air$ pip3
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 7, in <module>
from pip import main
ImportError: No module named 'pip'
air$ cat /usr/local/bin/pip3
#!/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/bin/python3.4
# -*- coding: utf-8 -*-
import re
import sys
from pip import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
You have to install openssl first, than python. So openssl support will work (python compiles with ssl support if openssl is available at install time.).
In addition to Mathias' answer, you also need to make sure that the following environment variables are set before compiling python3:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include

Python 3.3.4 and virtualenv creation on Windows: ImportError: No module named 'pip'

I need virtualenv for Pyramid on XP.
pip installs fine and so does virtualenv
But when I try to create an instance directory, virtualenv bombs.
I uninstalled and re-installed virtualenv, but I keep getting the same problem.
Any ideas?
C:\>pip --version
pip 1.5.4 from C:\Python334\lib\site-packages (python 3.3)
C:\>virtualenv --version
1.11.4
C:\>virtualenv venv
Using base prefix 'C:\\Python334'
New python executable in venv\Scripts\python.exe
Installing setuptools, pip...
Complete output from command C:\venv\Scripts\python.exe -c "import sys, pip; s
ys...d\"] + sys.argv[1:]))" setuptools pip:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'pip'
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
File "C:\Python334\lib\runpy.py", line 160, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python334\lib\runpy.py", line 73, in _run_code
exec(code, run_globals)
File "C:\Python334\Scripts\virtualenv.exe\__main__.py", line 9, in <module>
File "C:\Python334\lib\site-packages\virtualenv.py", line 824, in main
symlink=options.symlink)
File "C:\Python334\lib\site-packages\virtualenv.py", line 992, in create_envir
onment
install_wheel(to_install, py_executable, search_dirs)
File "C:\Python334\lib\site-packages\virtualenv.py", line 960, in install_wheel
'PIP_NO_INDEX': '1'
File "C:\Python334\lib\site-packages\virtualenv.py", line 902, in call_subproc
ess
% (cmd_desc, proc.returncode))
OSError: Command C:\venv\Scripts\python.exe -c "import sys, pip; sys...d\"] + sy
s.argv[1:]))" setuptools pip failed with error code 1
C:\>
Python 2.7.9 and later (on the python2 series), and Python 3.4 and later include pip by default [1], so you may have pip already.
(https://pip.pypa.io/en/latest/installing.html)
So, to install pip, securely download get-pip.py. (https://bootstrap.pypa.io/get-pip.py)
Then run the following (which may require administrator access):
python get-pip.py

Categories