简体   繁体   English

使用Pip和Homebrew安装Virtualenv时出错

[英]Error With Installing Virtualenv With Pip and Homebrew

I am trying to get a nice clean Python environment setup on OSX 10.9. 我正在尝试在OSX 10.9上获得良好的干净Python环境设置。 I've installed Python with Homebrew and set my PATH variables so... 我已经用Homebrew安装了Python,并设置了PATH变量,以便...

> which python
/usr/local/bin/python

and

> which pip
/usr/local/bin/pip

so when I look at my /usr/local/bin : 所以当我看我的/ 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: 我在/ 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. 我认为通过使用Homebrew,我可以使用pip并避免使用sudo安装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.). 我从/usr/local/bin删除了所有与virtualenv相关的内容(由于某种原因,它们已安装在root下,这导致了我的权限问题。)。

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/ 然后我做了一个pip uninstall virtualenv来摆脱pip uninstall virtualenv的其他实例,因为/usr/local/lib/python2.7/site-packages/仍然有一个

Then a simple pip install virtualenv and things work fine now! 然后一个简单的pip install virtualenv ,一切正常!

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. HomeBrew很有可能做了一些魔术,因此运行brew install允许写入/usr/local/bin ,但是此特权不适用于普通命令。 This is a guess, I didn't investigate this further. 这是一个猜测,我没有对此做进一步调查。

Install virtualenv with brew : 使用brew安装virtualenv

 brew install pyenv-virtualenv

This command: 该命令:

pip install virtualenv pip安装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. 从$ PATH环境变量的第一个目录运行pip,该环境变量通常是系统范围的,因此,当您以这种方式运行时,您将尝试全局安装它。

You should install you your environment in your $HOME directory: 您应该在$ HOME目录中安装环境:

virtualenv $HOME/myvirpython

and later: 然后:

$HOME/myvirpython/bin pip install something

Additionally you should read this: 另外,您应该阅读以下内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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