Python mkvirtualenv:找不到命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/25774829/
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
mkvirtualenv: command not found
提问by aaragon
I'm new to Python virtual environments, so after reading this tutorialI tried to create my first environment using virtualenvwrapper. My python3 installation is at the bare bones now:
我是 Python 虚拟环境的新手,因此在阅读本教程后,我尝试使用virtualenvwrapper. 我的 python3 安装现在是最基本的:
$ pip3 list
argparse (1.2.1)
pip (1.5.6)
setuptools (2.1)
stevedore (0.15)
virtualenv (1.11.6)
virtualenv-clone (0.2.5)
virtualenvwrapper (4.3.1)
As suggested by the tutorial, I added the following lines to my .bashrcfile:
按照教程的建议,我在.bashrc文件中添加了以下几行:
export WORKON_HOME=$HOME/.virtualenvs
source /Library/Frameworks/Python.framework/Versions/3.4/bin/virtualenvwrapper_lazy.sh
which results in the following message when I open a new Terminal:
当我打开一个新终端时,会产生以下消息:
Last login: Wed Sep 10 22:33:17 on ttys006
-bash: _VIRTUALENVWRAPPER_API: unbound variable
-bash: VIRTUALENVWRAPPER_SCRIPT: unbound variable
-bash: VIRTUALENVWRAPPER_SCRIPT: unbound variable
-bash: _VIRTUALENVWRAPPER_API: unbound variable
-bash: _VIRTUALENVWRAPPER_API: unbound variable
complete: usage: complete [-abcdefgjksuv] [-pr] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [name ...]
I don't understand what the problem is, but clearly the source /Library/Frameworks/Python.framework/Versions/3.4/bin/virtualenvwrapper_lazy.shline fails because then I can't even find the mkvirtualenvcommand:
我不明白问题是什么,但显然该source /Library/Frameworks/Python.framework/Versions/3.4/bin/virtualenvwrapper_lazy.sh行失败了,因为那时我什至找不到mkvirtualenv命令:
$ mkvirtualenv test1 -p /usr/bin/python3.3
-bash: mkvirtualenv: command not found
I found this postand this one, with similar problems, but none of them gave me a solution.
回答by pkoli
I added the following in my .bashrc, referring this
我在我的 .bashrc 中添加了以下内容,参考这个
export PATH=/usr/local/bin:$PATH
source /usr/local/bin/virtualenvwrapper.sh
Now mkvirtualenv works-
现在 mkvirtualenv 工作-
pkoli@pkoli-SVE15136CNB:~/Desktop$ mkvirtualenv BUGS
Using base prefix '/usr'
New python executable in BUGS/bin/python3
Also creating executable in BUGS/bin/python
Installing setuptools, pip...done.
回答by Nguyen Xuan
I ran into the same problem and I fixed it with by following the tutorial:
我遇到了同样的问题,并按照教程修复了它:
http://exponential.io/blog/2015/02/10/install-virtualenv-and-virtualenvwrapper-on-ubuntu/
http://exponential.io/blog/2015/02/10/install-virtualenv-and-virtualenvwrapper-on-ubuntu/
Part 1: Install the required packages
第 1 部分:安装所需的软件包
sudo apt-get install python-pip python-dev build-essential
sudo apt-get install python-pip python-dev build-essential
sudo pip install virtualenv virtualenvwrapper
sudo pip install virtualenv virtualenvwrapper
sudo pip install --upgrade pip
sudo pip install --upgrade pip
Part 2: Setup virtualenvwrapper in ~/.bashrc.
第 2 部分:在 ~/.bashrc 中设置 virtualenvwrapper。
I used vimto edit ~/.bashrc.
我用vim来编辑 ~/.bashrc。
Firstly, install vim with the command:
首先,使用以下命令安装vim:
sudo apt-get install vim
sudo apt-get install vim
Secondly, edit ~/.bashrc
其次,编辑 ~/.bashrc
vi .bashrc
vi .bashrc
enter [Shift] + [g]//G(shift + g): to go the end of the file
enter [Shift] + [g]//G(shift + g): to go the end of the file
enter [a]//Type ato edit the file
enter [a]//Type ato edit the file
Then insert three lines:
然后插入三行:
export WORKON_HOME=~/virtualenvs
export VIRTUALENVWRAPPER_PYTHON=[link-to-python-folder]
source /usr/local/bin/virtualenvwrapper.sh
export WORKON_HOME=~/virtualenvs
export VIRTUALENVWRAPPER_PYTHON=[link-to-python-folder]
source /usr/local/bin/virtualenvwrapper.sh
where [link-to-python-folder]can be, for example: 
[link-to-python-folder]可以在哪里,例如:
- if you are using python 3,
- 如果您使用的是 python 3,
export VIRTUALENVWRAPPER_PYTHON=/user/bin/python3
export VIRTUALENVWRAPPER_PYTHON=/user/bin/python3
- if you are using python 2,
- 如果您使用的是 python 2,
export VIRTUALENVWRAPPER_PYTHON=/user/bin/python
export VIRTUALENVWRAPPER_PYTHON=/user/bin/python
Next,
enter [Esc]then :wq
下一个,
enter [Esc]then :wq
The Esckey means return the command line, :wqmeans save the changes and exit vi.
该Esc键键表示返回命令行:WQ手段保存更改并退出VI。
Part 3: Enable the virtual environment.
第 3 部分:启用虚拟环境。
source ~/.bashrc
source ~/.bashrc
mkdir -p $WORKON_HOME
mkdir -p $WORKON_HOME
Now, you can try again with mkvirtualenv:
现在,您可以使用mkvirtualenv再试一次:
mkvirtualenv your_project
mkvirtualenv your_project
- To enable the 'your_project' virtual environment: - workon your_project
- To exit it: - deactivate
- 要启用“your_project”虚拟环境: - workon your_project
- 要退出它: - deactivate
I noticed that when I installed separately virtualenv and virtualenvwrapper (with two times of 'sudo pip install'), I failed when run source ~/.bashrcbecause of a failure of the importing the module virtualenvwrapper.hook_loader, so although you really installed virtualenvand virtualenvwrapper, let try it one more time with sudo pip install virtualenv virtualenvwrapper.
我注意到,当我分别安装 virtualenv 和 virtualenvwrapper(两次 'sudo pip install')时,source ~/.bashrc由于导入模块virtualenvwrapper.hook_loader失败,我在运行时失败了,所以虽然你真的安装了virtualenv和virtualenvwrapper,让我们试试再用一次sudo pip install virtualenv virtualenvwrapper。
Hope you find it useful!
希望你觉得它有用!
回答by akkhil
export WORKON_HOME=~/Virtualenvs
export PROJECT_HOME=~/Devel
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
source /usr/local/bin/virtualenvwrapper.sh
If you have a clean installation of virtualenv and virtualenvwrapper, then this should work in mac OS. It did for me.
如果您全新安装了 virtualenv 和 virtualenvwrapper,那么这应该适用于 mac OS。它对我有用。

