错误“virtualenv : command not found”但安装位置在 PYTHONPATH
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39964635/
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
Error "virtualenv : command not found" but install location is in PYTHONPATH
提问by Pravesh Jain
This has been driving me crazy for the past 2 days.
I installed virtualenv on my Macbook using pip install virtualenv
.
But when I try to create a new virtualenv using virtualenv venv
, I get the error saying "virtualenv : command not found".
在过去的 2 天里,这让我发疯了。我使用pip install virtualenv
. 但是当我尝试使用 创建一个新的 virtualenv 时virtualenv venv
,我收到错误消息“virtualenv : command not found”。
I used pip show virtualenv
and the location of the installation is "Location: /usr/local/lib/python2.7/site-packages" but I can't figure out where the executable is. I tried dozens other similar looking posts but those solutions do not work for me.
我使用过pip show virtualenv
并且安装的位置是“位置:/usr/local/lib/python2.7/site-packages”,但我无法弄清楚可执行文件在哪里。我尝试了许多其他类似的帖子,但这些解决方案对我不起作用。
Any ideas what might be going wrong here?
任何想法这里可能会出现什么问题?
回答by Pravesh Jain
The only workable approach I could figure out (with help from @Gator_Python was to do python -m virtualenv venv
. This creates the virtual environment and works as expected.
我能想到的唯一可行的方法(在@Gator_Python 的帮助下是 do python -m virtualenv venv
。这会创建虚拟环境并按预期工作。
I have custom python installed and maybe that's why the default approach doesn't work for me.
我安装了自定义 python,也许这就是默认方法对我不起作用的原因。
回答by Mian Asbat Ahmad
On macOS Mojave
First check python is in the path.python --version
Second check pip is installed.pip --version
If it is not installed.brew install pip
Third install virtualenvsudo -H pip install virtualenv
在 macOS Mojave 上,
首先检查 python 是否在路径中。python --version
安装了第二个检查点。pip --version
如果没有安装。brew install pip
第三次安装virtualenvsudo -H pip install virtualenv
回答by sytech
As mentioned in the comments, you've got the virtualenv module installed properly in the expected environment since python -m venv
allows you to create virtualenv's.
正如评论中提到的,您已经在预期的环境中正确安装了 virtualenv 模块,因为它python -m venv
允许您创建 virtualenv。
The fact that virtualenv
is not a recognized command is a result of the virtualenv.py
not being in your system PATH and/or not being executable. The root cause could be outdated distutils or setuptools.
virtualenv
不是可识别命令的事实是由于virtualenv.py
不在您的系统 PATH 中和/或不可执行。根本原因可能是过时的 distutils 或 setuptools。
You should attempt to locate the virtualenv.py
file, ensure it is executable (chmod +x
) and that its location is in your system PATH. On my system, virtualenv.py
is in the ../Pythonx.x/Scripts
folder, but this may be different for you.
您应该尝试定位该virtualenv.py
文件,确保它是可执行的 ( chmod +x
) 并且它的位置在您的系统 PATH 中。在我的系统上,virtualenv.py
位于../Pythonx.x/Scripts
文件夹中,但这对您来说可能有所不同。
回答by Lal Krishna
For Python 3
对于 Python 3
python3 -m virtualenv venv
回答by Bill
Could it be that you are using Anaconda package manager? If so, then it has it's own virtual environment system which you setup as follows:
可能是您正在使用 Anaconda 包管理器吗?如果是这样,那么它有自己的虚拟环境系统,您可以按如下方式设置:
conda create --name venv
回答by watashiSHUN
I had the same issue (although on ubuntu), a simple solution is instead of doing pip install virtualenv
, you precede the commend with "sudo".
我遇到了同样的问题(虽然在 ubuntu 上),一个简单的解决方案是,而不是做pip install virtualenv
,你在推荐之前加上“ sudo”。
A little inspection reveals the reason behind this fix:
pip install virtualenv
tries to put an executable under /usr/local/bin
so that it can be invoked from command line, but it failed because only root has write permission to that directory
pip install virtualenv
试图将一个可执行文件放在下面,/usr/local/bin
以便它可以从命令行调用,但它失败了,因为只有 root 对该目录有写权限
an alternative is pip install --user virtualenv
, here are some further readings 1,2
回答by Damien Ferey
I succeded creating manually a link to location/virtualenv.py in /usr/local/bin, naming it virtualenv and adding +x attribute on file
我成功地在 /usr/local/bin 中手动创建了指向位置/virtualenv.py的链接,将其命名为 virtualenv 并在文件上添加 +x 属性
? ~ pip show virtualenv
Name: virtualenv
Version: 16.6.0
Summary: Virtual Python Environment builder
Home-page: https://virtualenv.pypa.io/
Author: Ian Bicking
Author-email: [email protected]
License: MIT
Location: /home/prsadev/.local/lib/python2.7/site-packages
Requires:
~ chmod +x /home/prsadev/.local/lib/python2.7/site-packages/virtualenv.py
~ sudo ln -sf /home/prsadev/.local/lib/python2.7/site-packages/virtualenv.py /usr/local/bin/virtualenv
回答by Amit Prajapati
I tried to have virtualenv at a random location & faced the same issue on a UBUNTU machine, when I tried to run my 'venv'. What solved my issue was :-
当我尝试运行我的“venv”时,我试图在随机位置使用 virtualenv 并在 UBUNTU 机器上遇到同样的问题。解决我的问题的是:-
$virtualenv -p python3 venv
$virtualenv -p python3 venv
Also,instead of using $activate
try :-
$source activate
If you look at the activate script(or $cat activate
), you will find the same in comment.
另外,不要使用 $ activate
try :-
$source activate
如果您查看激活脚本(或 $ cat activate
),您会在注释中找到相同的内容。