Python 如何将 virtualenv 添加到路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15453793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add virtualenv to path
提问by Michael Trouw
I am trying to find out why my virtualenvand/or virtualenvwrapper - installed using pipusing homebrew- cannot be found. I think it's because it's not added to my PATH:
我试图找出为什么我的virtualenv和/或virtualenv包装器 - 使用pipusing安装homebrew- 找不到。我认为这是因为它没有添加到我的 PATH 中:
$ which virtualenv
$
and:
和:
$ virtualenv someDir
$ -bash: virtualenv: command not found
I installed pip using homebrew, and virtualenvusing pip, without problems. I tried reinstalling virtualenv, but that did not work either.
How do I know what path to add to PATH? Just the path that virtualenv.pyseems to be installed into? That seems to be:
我安装 pip 使用homebrew, 并virtualenv使用pip, 没有问题。我尝试重新安装virtualenv,但这也不起作用。我怎么知道要添加到什么路径PATH?只是virtualenv.py似乎安装到的路径?那似乎是:
/usr/local/lib/python2.7/site-packages/virtualenv.py
I also found this guide, which suggests this:
我还找到了这个指南,它表明了这一点:
$ ln -s ../Cellar/python/2.7/Frameworks/Python.framework/Versions/2.7/bin/virtualenv virtualenv
However, it does not help me run virtualenv. I am on Mac OSX 10.7.5 (Lion).
但是,它不能帮助我运行virtualenv. 我在 Mac OSX 10.7.5 (Lion) 上。
采纳答案by Michael Trouw
It seems that I myself am the exception to the rule for almost all 'simple' installation procedures. For some reason, it WAS a path related issue:
似乎我自己是几乎所有“简单”安装程序规则的例外。出于某种原因,这是一个与路径相关的问题:
I ran brew info python, which outputted a lot of information. At the bottom I found this:
我跑了brew info python,输出了很多信息。在底部我发现了这个:
Executable python scripts will be put in:
/usr/local/share/python
so you may want to put "/usr/local/share/python" in your PATH, too.
I added that to my PATH in /etc/launchd.confand ~/.bashrcand lo and behold:
我将它添加到我的 PATH 中/etc/launchd.conf,~/.bashrc然后瞧瞧:
$ which virtualenv
tells me:
告诉我:
"/usr/local/share/python/virtualenv"
I still don't know why I couldn't find any pointers in the right direction, online, anywhere? Is pip install virtualenvsupposed to add to the PATH itself? If so, why not on my system? Why did @bibhas tell me explicitly it was not a path issue?
我仍然不知道为什么我找不到任何指向正确方向的指针,在线,任何地方?是pip install virtualenv应该添加到的路径呢?如果是这样,为什么不在我的系统上?为什么@bibhas 明确告诉我这不是路径问题?
回答by D.Shawley
The module in /usr/local/lib/python2.7/site-packagesis imported by a short script that uses pkg_resources.load_entry_pointto run the application. The utility script should be in /usr/local/bin.
模块 in/usr/local/lib/python2.7/site-packages由pkg_resources.load_entry_point用于运行应用程序的简短脚本导入。实用程序脚本应该在/usr/local/bin.
回答by Kurt
In your .bashrc you need to have:
在您的 .bashrc 中,您需要:
export WORKON_HOME=~/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
回答by manojlds
This solution will give you an alternate tool to use and solve your virtualenvproblem at the same time.
此解决方案将为您提供一个替代工具来同时使用和解决您的virtualenv问题。
Use pythonbrew. It is inspired from rvmin the ruby world and is helpful in managing pythons on your system and also wrap virtualenvcommands to provide virtual environment management. I use it Mountain Lion for my development purposes and have had no problems. More details (on my blog): http://stacktoheap.com/blog/2013/03/11/why-use-virtualenv-when-there-is-pythonbrew/
使用pythonbrew。它的灵感来自rvmruby 世界,有助于管理系统上的 python,还可以包装virtualenv命令以提供虚拟环境管理。我将 Mountain Lion 用于我的开发目的,并且没有遇到任何问题。更多细节(在我的博客上):http: //stacktoheap.com/blog/2013/03/11/why-use-virtualenv-when-there-is-pythonbrew/
回答by Alex Wachira
Had the same issue after pip install virtualenv
之后有同样的问题 pip install virtualenv
When I inspected python ls -la /usr/local/bin/pythonI found it was symbolically linked to /Library/Frameworks/Python.framework/Versions/2.7/bin/python
当我检查 python 时,ls -la /usr/local/bin/python我发现它象征性地链接到/Library/Frameworks/Python.framework/Versions/2.7/bin/python
When I cd in that directory I also found the virtualenv executable and
当我在该目录中 cd 时,我还找到了 virtualenv 可执行文件和
Fixed it by
固定它
cd /Library/Frameworks/Python.framework/Versions/2.7/binln virtualenv /usr/local/bin/virtualenv
cd /Library/Frameworks/Python.framework/Versions/2.7/binln virtualenv /usr/local/bin/virtualenv
Sidenote: I also happen to have a python installation in /System/Library/Frameworks/Python.framework/Versions/2.7/bin
旁注:我也碰巧在 /System/Library/Frameworks/Python.framework/Versions/2.7/bin
I believe that's the one that came with OSX
我相信那是 OSX 自带的
回答by mamian
My idea is to add your virtualenv position to the BASH PATH
我的想法是将您的 virtualenv 位置添加到 BASH PATH
export PATH=$PATH:/usr/local/python2.7/binOr change your position
export PATH=$PATH:/usr/local/python2.7/bin或者改变你的位置
回答by Leepyng Chen
I solved it by: At first find out it located at /usr/local/python3 and then I fix it by the command: ln virtualenv /usr/local/bin/virtualenv
我通过以下方式解决了它:首先找到它位于 /usr/local/python3 然后我通过命令修复它:ln virtualenv /usr/local/bin/virtualenv
回答by Fandango68
For those with Python 2.7, I came across this as well, and solved it by simply putting the following line into the \etc\pathsfile (may need to $ sudo chmodit first):
对于那些使用 Python 2.7 的人,我也遇到了这个问题,并通过简单地将以下行放入\etc\paths文件中来解决它(可能$ sudo chmod首先需要它):
/Library/Frameworks/Python.framework/Versions/2.7/bin
Save the change and start a new Terminal session. Check it with echo $PATH
保存更改并开始新的终端会话。检查它echo $PATH
回答by rokrfellr
(Mac / Linux specific) So I got an error message when I did a pip3 install --user --upgrade virtualenv telling me that I did not have Users/home/Library/Python/3.7/bin in my PATH. So I simply added it.
(特定于 Mac/Linux)因此,当我执行 pip3 install --user --upgrade virtualenv 时收到一条错误消息,告诉我我的 PATH 中没有 Users/home/Library/Python/3.7/bin。所以我简单地添加了它。
If this is on the Mac, the following did it for me
如果这是在 Mac 上,以下为我做了
vi ~/.bash_profile
vi ~/.bash_profile
PATH="/Users/home/Library/Python/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
PATH="/Users/home/Library/Python/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
restart your terminal and type virtualenv env and that should do it.
重启你的终端并输入 virtualenv env 就可以了。

