简体   繁体   中英

Error With Installing Virtualenv With Pip and Homebrew

I am trying to get a nice clean Python environment setup on OSX 10.9. I've installed Python with Homebrew and set my PATH variables so...

> which python
/usr/local/bin/python

and

> which pip
/usr/local/bin/pip

so when I look at my /usr/local/bin :

pip -> ../Cellar/python/2.7.6/bin/pip
python -> ../Cellar/python/2.7.6/bin/python

then when I run:

> pip install virtualenv

I get permission errors on /usr/local/bin/virtualenv:

...
running install_scripts

Installing virtualenv script to /usr/local/bin

error: /usr/local/bin/virtualenv: Permission denied

I thought that by using Homebrew I could use pip and avoid using sudo to install virtualenv. Am I doing something wrong here?

Ok! I managed to fix this myself.

I deleted all the virtualenv related things from /usr/local/bin (they had been installed under root for some reason and this was causing my permission issues.).

Then I did a pip uninstall virtualenv to get rid of other instances of virtualenv, as there was still one in /usr/local/lib/python2.7/site-packages/

Then a simple pip install virtualenv and things work fine now!

Most likely HomeBrew does some magic so that running brew install allows writing to /usr/local/bin , but this privilege is not available to normal commands. This is a guess, I didn't investigate this further.

Install virtualenv with brew :

 brew install pyenv-virtualenv

This command:

pip install virtualenv

runs pip from your first directory from $PATH environment variable, which is usually system wide, thus when you run in this way - you are trying to install it globall.

You should install you your environment in your $HOME directory:

virtualenv $HOME/myvirpython

and later:

$HOME/myvirpython/bin pip install something

Additionally you should read this:

https://docs.brew.sh/Homebrew-and-Python

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM