简体   繁体   English

mkvirtualenv:找不到命令

[英]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/

Part 1: Install the required packages第 1 部分:安装所需的软件包

sudo apt-get install python-pip python-dev build-essential

sudo pip install virtualenv virtualenvwrapper

sudo pip install --upgrade pip

Part 2: Setup virtualenvwrapper in ~/.bashrc.第 2 部分:在 ~/.bashrc 中设置 virtualenvwrapper。

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]可以是,例如:

  • if you are using python 3,如果您使用的是 python 3,

export VIRTUALENVWRAPPER_PYTHON=/user/bin/python3

  • if you are using python 2,如果您使用的是 python 2,

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

Part 3: Enable the virtual environment.第 3 部分:启用虚拟环境。

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时失败了,所以虽然你真的安装了virtualenvvirtualenvwrapper ,让我们用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.

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