[英]mkvirtualenv: command not found
I'm new to Python virtual environments, so after reading this tutorial I tried to create my first environment using virtualenvwrapper
.我是 Python 虚拟环境的新手,因此在阅读本教程后,我尝试使用
virtualenvwrapper
创建我的第一个环境。 My python3 installation is at the bare bones now:我的 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 .bashrc file:按照教程的建议,我在.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.sh
line fails because then I can't even find the mkvirtualenv
command:我不明白问题是什么,但很明显
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 post and this one , with similar problems, but none of them gave me a solution.我发现这个职位和这一个,类似的问题,但没有人给我一个解决方案。
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.
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/
sudo apt-get install python-pip python-dev build-essential
sudo pip install virtualenv virtualenvwrapper
sudo pip install --upgrade pip
I used vim to edit ~/.bashrc.我用vim来编辑 ~/.bashrc。
Firstly, install vim with the command:首先,使用以下命令安装vim:
sudo apt-get install vim
Secondly, edit ~/.bashrc其次,编辑 ~/.bashrc
vi .bashrc
enter [Shift] + [g] // G (shift + g): to go the end of the file
enter [a] //Type a to edit the file
Then insert three lines:然后插入三行:
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]
可以是,例如:
export VIRTUALENVWRAPPER_PYTHON=/user/bin/python3
export VIRTUALENVWRAPPER_PYTHON=/user/bin/python
Next, enter [Esc] then :wq
接下来,
enter [Esc] then :wq
The Esc key means return the command line, :wq means save the changes and exit vi . Esc键表示返回命令行, :wq表示保存更改并退出vi 。
source ~/.bashrc
mkdir -p $WORKON_HOME
Now, you can try again with mkvirtualenv :现在,您可以使用mkvirtualenv再试一次:
mkvirtualenv your_project
To enable the 'your_project' virtual environment:要启用“your_project”虚拟环境:
workon your_project
To exit it:要退出它:
deactivate
I noticed that when I installed separately virtualenv and virtualenvwrapper (with two times of 'sudo pip install'), I failed when run source ~/.bashrc
because of a failure of the importing the module virtualenvwrapper.hook_loader , so although you really installed virtualenv and virtualenvwrapper , let try it one more time with sudo pip install virtualenv virtualenvwrapper
.我注意到当我分别安装 virtualenv 和 virtualenvwrapper(两次 'sudo pip install')时,由于导入模块virtualenvwrapper.hook_loader失败,我在运行
source ~/.bashrc
时失败了,所以虽然你真的安装了virtualenv和virtualenvwrapper ,让我们用sudo pip install virtualenv virtualenvwrapper
再试一次。
Hope you find it useful!希望你觉得它有用!
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.如果您全新安装了 virtualenv 和 virtualenvwrapper,那么这应该适用于 mac OS。 It did for me.
它对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.