Issue
I'm having a little trouble with virtualenv on Mac OS X Yosemite. After I couldn't run virtualenv at all first, I installed Python 3 via brew
(previously I installed it via the package on python.org). I linked this installation of python3, updated pip and ran pip3 install virtualenv
. When I try to run virtualenv (e.g. $ virtualenv --python=python3 ../virtualenv
), I get the following error message.
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 7, in <module>
from virtualenv import main
File "/usr/local/bin/virtualenv.py", line 7, in <module>
from virtualenv import main
ImportError: cannot import name 'main'
Can anybody help me with this?
Solution
Your virtualenv executable /usr/local/bin/virtualenv
is importing the virtualenv package /usr/local/bin/virtualenv.py
. My guess is that package is not the one the executable should really be importing. The reason it is choosing that one is because it is in the same directory.
First, check where the real virtualenv package is. In the python3 terminal:
>>> import virtualenv
>>> virtualenv.__file__
If it is not /usr/local/bin/virtualenv.py
, then the simplest way to get /usr/local/bin/virtualenv
to import it instead of /usr/local/bin/virtualenv.py
is to delete /usr/local/bin/virtualenv.py
(or so you can easily undo this if it doesn't work, simply rename virtualenv.py
to something else like xvirtualenvx.py
).
Answered By - hansmosh Answer Checked By - Terry (WPSolving Volunteer)