Problem with virtualenv in Mac OS X
Solution 1
If you continue to have trouble with virtualenv
, you might try pythonbrew, instead. It's an alternate solution to the same problem. It works more like Ruby's rvm: It builds and creates an entire instance of Python, under $HOME/.pythonbrew
, and then sets up some bash functions that allow you to switch easily between versions. Where virtualenv
shadows the system version of Python, using symbolic links as part of its solution, pythonbrew
builds entirely self-contained installations of Python.
I used virtualenv
for years. It's a decent solution, but I've switched to pythonbrew
lately. Having completely self-contained Python instances means that installing a new one takes awhile (since pythonbrew
actually compiles Python from scratch), but the self-contained nature of each installation appeals to me. And disk is cheap.
Solution 2
Just in case there's someone still seeking for the answer.
I ran into this same problem just today and realized since I already have Anaconda installed, I should not have used pip install virtualenv
to install virtual environment as this would give me the error message when trying to initiate it later. Instead, I tried conda install virtualenv
then entered virtualenv env_mysite
and problem solved.
Solution 3
Like @RyanWilcox mentioned, you might be inadvertently pointing virtualenv
to the wrong Python installation. Virtualenv comes with a -p
flag to let you specify which interpreter to use.
In my case,
virtualenv test_env
threw the same error as yours, while
virtualenv -p python test_env
worked perfectly.
If you call virtualenv -h
, the documentation for the -p
flag will tell you which python it thinks it should be using; if it looks wonky, try passing -p python
. For reference, I'm on virtualenv 1.11.6.
Solution 4
In case anyone in the future runs into this problem - this is caused by your default Python distribution being conda. Conda has it's own virtual env set up process but if you have the conda distribution of python and still wish to use virtualenv here's how:
Find the other python distribution on your machine:
ls -ls /usr/bin/python*
Take note of the availble python version that is not conda and run the code below (note for python 3 and above you have to upgrade virtualenv first):
virtualenv -p python2.7(or your python version) flaskapp
Solution 5
I've run across this problem myself. I wrote down the instructions in a README, which I have pasted below....
I have found there are two things that work:
- Make sure you're running the latest virtualenv (1.5.1, of this writting)
-
If you're using a non system Python as your standard Python (which python to check) Forcefully use the System supplied one.
Instead of
virtualenv thing
use/usr/bin/python2.6 PATH/TO/VIRTUALENV thing
(or whateverwhich python
returned to you - this is what it did for me when I ran into this issue)
gigimon
Updated on July 09, 2022Comments
-
gigimon almost 2 years
I've installed
virtualenv
viapip
and get this error after creating a new environment:selenium:~ auser$ virtualenv new New python executable in new/bin/python ERROR: The executable new/bin/python is not functioning ERROR: It thinks sys.prefix is u'/System/Library/Frameworks/Python.framework/ Versions/2.6' (should be '/Users/user/new') ERROR: virtualenv is not compatible with this system or executable
In my environment:
PYTHONPATH=/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages PATH=/System/Library/Frameworks/Python.framework/Versions/2.6/bin:/Library/Frameworks/Python.framework/Versions/2.6/bin:/Library/Frameworks/Python.framework/Versions/2.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
How can I repair this?
Thanks.
-
gigimon about 13 yearsNot understand, what is bootstrap.py? I'm use system Python: which python /System/Library/Frameworks/Python.framework/Versions/2.6/bin/python
-
gigimon about 13 yearsThx, I'm try use pythonbew, but later :)
-
Jeff over 12 yearsWhat's the difference between pythonbrew and virtualenv? Why when I am using pythonbrew I still need to use virtualenv to create isolated env? I asked a question here stackoverflow.com/questions/8256723/…
-
Brian Clapper over 12 yearsJeff, I added an answer to the question that you referred to. See stackoverflow.com/a/8348440/53495
-
Matthew Schinckel almost 11 yearsThis fixed my issue: just needed a newer virtualenv.
-
KartikKannapur almost 8 yearsI ran into the same error. Did you find a solution?
-
Admin over 7 yearsI just got this error too! Seems like there's no solution. I'm using anaconda, are you guys using the system python or anaconda?
-
Jonathan Stray about 7 yearsDownvoted as I prefer the solution to getting virtualenv working -- for me it was
conda install virtualenv
as the other answer. -
Chris about 7 yearsI already had anaconda installed too. I uninstalled from pip and installed with conda: pip uninstall virtualenv -- conda install virtualenv -- virtualenv my_project
-
agentcurry almost 7 yearsWorked like a charm. Thank you, kind sir!
-
Asanka over 6 yearsSaved my day. Thank you wastetime909
-
nano2nd about 6 yearsSo glad I scrolled down :)
-
Oğuz Şerbetci almost 6 years
python brew
is no longer in active development. Do have a look atpyenv
,pipenv
andpipsi
. -
Oduvan almost 6 yearsdownvoted (as well as question itself), because what will be the next right answer for this author? "If you continue to have trouble with python, you might try ruby .... "