Python 错误:virtualenvwrapper 在您的路径中找不到 virtualenv
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31274642/
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: virtualenvwrapper could not find virtualenv in your path
提问by vmonteco
I'm trying to create a virtualenv with virtualenvwrapper
, but when I use mkvirtualenv
I get the following :
我正在尝试创建一个 virtualenv virtualenvwrapper
,但是当我使用时,mkvirtualenv
我得到以下信息:
ERROR: virtualenvwrapper could not find virtualenv in your path
I assumed it was a PYTHONPATHproblem.
But if I do a pip show virtualenv
I get the following :
我认为这是PYTHONPATH问题。但如果我做一个pip show virtualenv
我得到以下内容:
---
Metadata-Version: 2.0
Name: virtualenv
Version: 13.1.0
Summary: Virtual Python Environment builder
Home-page: https://virtualenv.pypa.io/
Author: Jannis Leidel, Carl Meyer and Brian Rosner
Author-email: [email protected]
License: MIT
Location: /Volumes/Data/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages
Requires:
And here is my PYTHONPATH:
这是我的PYTHONPATH:
/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/bin:/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/bin:/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages:/Volumes/Data/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages:~/.brew/Cellar
/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/bin:/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/bin:/nfs/zfs -student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages:/Volumes/Data/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/ lib/python/site-packages:~/.brew/Cellar
It contains the directory containing virtualenv!
它包含包含 virtualenv 的目录!
(i-e : /Volumes/Data/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages)
(即:/Volumes/Data/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages)
My ~/.zshrccontains :
我的~/.zshrc包含:
export WORKON_HOME=~/Envs
export PROJECT_HOME=$HOME/Devel
source $HOME"/Library/Python/2.7/bin/virtualenvwrapper.sh"
EDIT :virtualenvwrapper.sh is written in bash, perhaps should I check my PATHinstead of my PYTHONPATH?
编辑:virtualenvwrapper.sh 是用 bash 编写的,也许我应该检查我的PATH而不是我的PYTHONPATH?
So, what could the problem be? How could I fix it?
那么,问题可能是什么?我怎么能修好呢?
Thank you in advance for your help.
预先感谢您的帮助。
采纳答案by vmonteco
I finally found out what the problem was :
我终于发现了问题所在:
virtualenvwrapper.shis written in BASHand not in Python. So virtualenvis called from a shell (zsh). I didn't have to bother about my PYTHONPATH, but about my PATH(I was already able to import virtualenv from my python shell anyway).
virtualenvwrapper.sh是用BASH编写的,而不是用Python编写的。所以virtualenv是从 shell ( zsh)调用的。我不必担心我的PYTHONPATH,而是我的PATH(无论如何我已经能够从我的 python shell 中导入 virtualenv )。
I just added the correct directory to my PATHand everything worked fine.
我刚刚将正确的目录添加到我的PATH 中,一切正常。
回答by Josh J
Your PYTHONPATH makes me think you have Homebrew installed. It sounds like virtualenvwrapper was installed with either your system pip or your homebrew pip while it is being executed with the opposite python interpreter.
你的 PYTHONPATH 让我觉得你安装了 Homebrew。听起来 virtualenvwrapper 是与您的系统 pip 或自制程序 pip 一起安装的,而它正在使用相反的 python 解释器执行。
回答by Slark
sudo find / -name "virtualenv"
Then I find the executable file path is:
/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/bin/virtualenv
Touch a soft link in the
/usr/local/bin/
directory or add the path to.bash_profile
, I prefer the former:sudo ln -s /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/bin/virtualenv /usr/local/bin/virtualenv
sudo find / -name "virtualenv"
然后我发现可执行文件路径是:
/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/bin/virtualenv
触摸
/usr/local/bin/
目录中的软链接或将路径添加到.bash_profile
,我更喜欢前者:sudo ln -s /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/bin/virtualenv /usr/local/bin/virtualenv
回答by Sudheer K
Re-installling virtualenv fixed my problem.
重新安装 virtualenv 解决了我的问题。
I had the same issue.
我遇到过同样的问题。
$ mkvirtualenv mysite
ERROR: virtualenvwrapper could not find virtualenv in your path
After a lot of time consuming efforts, I decided to re-install virtualenv.
经过大量耗时的努力,我决定重新安装virtualenv。
sudo apt install virtualenv
This fixed my issues. I already had virtualenv installed. But I think it got broken or met with some errors.
这解决了我的问题。我已经安装了 virtualenv。但我认为它坏了或遇到了一些错误。
回答by alamin
- Find where is your
virtualenvwrapper
located. in my case
- 查找您所在的
virtualenvwrapper
位置。就我而言
~/.local/bin
May be it's installed in
可能是安装在
/usr/local/bin/
It totally depends on the System or Package Manager you are using.
这完全取决于您使用的系统或包管理器。
- Add this path in your shell configuration
.bashrc
or.zshrc
or whatever by simply
- 在你的shell配置中添加这条路径
.bashrc
或.zshrc
或任何通过简单
PATH=$PATH:<directory_you_want_to_add>
for example
例如
PATH=$PATH:~/.local/bin
Also add the following configuration in .bashrc
or .zshrc
还添加以下配置.bashrc
或.zshrc
# the path you want your virtual environments to be saved and loaded from
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/<project_folder>
# most important, this is the program which loads virtualenv
# please update the path where virtualenvwrapper.sh is located
source /usr/local/bin/virtualenvwrapper.sh
Don't Forget to restart the shell.. or reload the configuration...
不要忘记重新启动shell .. 或重新加载配置...
To test whether it worked
测试它是否有效
mkvirtualenv test
if you see a test environment created then everything is ok.
如果您看到创建了一个测试环境,则一切正常。
For Detailed Installation Instructions go to the docs: virtualenvwrapper installation
有关详细的安装说明,请转到文档:virtualenvwrapper 安装
回答by Mikebarson
The way I did it was (using zsh) in this way:
我这样做的方式是(使用 zsh)以这种方式:
export PATH=$HOME/bin:/usr/local/bin:$PATH:/Users/username/Library/Python/2.7/bin:$PATH
export PATH=$HOME/bin:/usr/local/bin:$PATH:/Users/username/Library/Python/2.7/bin:$PATH
I simply located the file of virtualenvwrapper.sh inside this path /Users/username/Library/Python/2.7/bin:$PATH
我只是在这个路径中找到了 virtualenvwrapper.sh 文件 /Users/username/Library/Python/2.7/bin:$PATH
and added that path to PATH.
并将该路径添加到 PATH。
回答by Andrea
I am using python3 with virtualenvwrapper installed on Ubuntu 18.04, using pip3 without sudo. If you are in this situation, you might find interesting my configuration.
我在 Ubuntu 18.04 上使用安装了 virtualenvwrapper 的 python3,使用没有 sudo 的 pip3。如果您处于这种情况,您可能会发现我的配置很有趣。
In the end of my .bashrc I added the following rows (remember to put your usernamein the YOUR_USERNAME field):
在我的 .bashrc 的末尾,我添加了以下行(记住将您的用户名放在 YOUR_USERNAME 字段中):
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_VIRTUALENV=/home/YOUR_USERNAME/.local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
Then restart the cli with ctrl-D ctrl-T or reload the config with source ~/.bashrc
.
Then you should be good to go! Try the installation with:
然后使用 ctrl-D ctrl-T 重新启动 cli 或使用source ~/.bashrc
. 那么你应该很高兴去!尝试安装:
lsvirtualenv
mkvirtualenv test
workon test
deactivate
rmvirtualenv test
If you could create and delete a virtual environment, you are ready to go.
如果您可以创建和删除虚拟环境,那么您就可以开始了。
回答by asfawh
I had this same issues and tried many many things, what found as a solution is i had three pip version, pip with 2.7, 3.6 and 3.7. and 3.6 was the one works fine for many things, and install as sudo pip3.6 install virtualenv
, and it works fine.
I would suggest, check your pip version and tried to install based on your pip ver.
我遇到了同样的问题并尝试了很多东西,找到的解决方案是我有三个 pip 版本,2.7、3.6 和 3.7 的 pip。和 3.6 是一个在很多事情上都能正常工作的,并且安装为sudo pip3.6 install virtualenv
,它工作正常。我建议,检查您的 pip 版本并尝试根据您的 pip 版本进行安装。
回答by userx
ERROR: virtualenvwrapper could not find virtualenv in your path
This error means - program virtualenv
is not in your system path. This mostly happens if you install virtualenv
via pip without sudo. This kind of installation stores data in users local directory e.g ~/.local/bin
. So first step is to find where this binary present. You can do that using locate
program. First update its database using sudo updatedb
. Then run locate *bin/virtualenv
. Whatever path you get, append it in system path variable. This you can do by adding below line in your shell config file e.g. ~/.bashrc or ~/.zshenv
.
此错误意味着 - 程序virtualenv
不在您的系统路径中。如果您在virtualenv
没有 sudo 的情况下通过 pip安装,则通常会发生这种情况。这种安装将数据存储在用户本地目录中e.g ~/.local/bin
。所以第一步是找到这个二进制文件的位置。你可以使用locate
程序来做到这一点。首先使用sudo updatedb
. 然后运行locate *bin/virtualenv
。无论您获得什么路径,都将其附加到系统路径变量中。这可以通过在 shell 配置文件中添加以下行来完成,例如~/.bashrc or ~/.zshenv
.
export PATH=$PATH:/your/path
e.g.
例如
export PATH=$PATH:~/.local/bin
Now open new shell and try again. Error should be gone.
现在打开新外壳并重试。错误应该消失了。