Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
756 views
in Technique[技术] by (71.8m points)

macos - Can't pip install virtualenv in OS X 10.8 with brewed python 2.7

When trying to install virtualenv using a brewed python, I get the following error:

$ pip install virtualenv
Requirement already satisfied (use --upgrade to upgrade): 
  virtualenv in /Library/Python/2.7/site-packages/virtualenv-1.9.1-py2.7.egg
Cleaning up...

So clearly pip is somehow looking into the system python folder instead of the brewed one in /usr/local. How can I avoid this?

The brew doctor finds no problems, and the path priority is set ok.

I tried to remove the virtualenv package from the system python, so I could install virtualenv with the brewed pip. But then I could not create virtualenvs, as I got this error:

$ virtualenv datatransfer/
Traceback (most recent call last):
  File "/usr/local/bin/virtualenv", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2603, in <module>
    working_set.require(__requires__)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 666, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve
    raise DistributionNotFound(req)  # XXX put more info here
pkg_resources.DistributionNotFound: virtualenv==1.9.1

So I have not managed to avoid the system virtualenv.

What I am doing wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had the same problem and I managed to solve it by uninstalling any brew versions of Python and virtualenv

brew uninstall python
brew uninstall pyenv-virtualenv

Manually moving all the virtualenv* files I found under /usr/local/bin to another folder

sudo mkdir /usr/local/bin/venv-old
sudo mv /usr/local/bin/virtualenv* /usr/local/bin/venv-old/

Opening a new terminal tab and double-checking that I'm in a clean state

which python # => /usr/bin/python
which virtualenv # => virtualenv not found

And installing Python and virtualenv(wrapper) cleanly using the recommended method (here and here):

brew install python --with-brewed-openssl
# Open a new terminal tab now (to access /usr/local/bin/python)
pip install virtualenv
pip install virtualenvwrapper

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...