问题:找不到Virtualenv命令
virtualenv
尽管进行了种种尝试,我还是无法上班。我virtualenv
使用以下命令安装在MAC OS X上:
pip install virtualenv
并已将新增PATH
至我的.bash_profile
。每当我尝试运行该virtualenv
命令时,它都会返回:
-bash: virtualenv: command not found
每次运行pip install virtualenv
,它都会返回:
Requirement already satisfied (use --upgrade to upgrade): virtualenv in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
我了解在Mac中,virtualenv
应正确安装
/usr/local/bin
在virtualenv
确实安装/usr/local/bin
,但每当我试图运行virtualenv
命令,该命令没有找到。我也尝试virtualenv
在目录中运行命令/usr/local/bin
,它给我相同的结果:
-bash: virtualenv: command not found
这些是我添加到.bash_profile中的路径
export PATH=$PATH:/usr/local/bin
export PATH=$PATH:/usr/local/bin/python
export PATH=$PATH:/Library/Framework/Python.framework/Version/2.7/lib/site-packages
有任何解决方法吗?为什么会这样呢?
I couldn’t get virtualenv
to work despite various attempts. I installed virtualenv
on MAC OS X using:
pip install virtualenv
and have also added the PATH
into my .bash_profile
. Every time I try to run the virtualenv
command, it returns:
-bash: virtualenv: command not found
Every time I run pip install virtualenv
, it returns:
Requirement already satisfied (use --upgrade to upgrade): virtualenv in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
I understand that in mac, the virtualenv
should be correctly installed in
/usr/local/bin
The virtualenv
is indeed installed in /usr/local/bin
, but whenever I try to run the virtualenv
command, the command is not found. I’ve also tried to run the virtualenv
command in the directory /usr/local/bin
, and it gives me the same result:
-bash: virtualenv: command not found
These are the PATHs I added to my .bash_profile
export PATH=$PATH:/usr/local/bin
export PATH=$PATH:/usr/local/bin/python
export PATH=$PATH:/Library/Framework/Python.framework/Version/2.7/lib/site-packages
Any workarounds for this? Why is this the case?
回答 0
如果您使用
pip install virtualenv
你需要跑步
sudo /usr/bin/easy_install virtualenv
把它放进去/usr/local/bin/
。
上面的目录默认情况下应该在您的目录中PATH
;否则,请相应地编辑您的.zshrc
(或。bashrc
)。
If you installed it with
pip install virtualenv
You need to run
sudo /usr/bin/easy_install virtualenv
which puts it in /usr/local/bin/
.
The above directory by default should be in your PATH
; otherwise, edit your .zshrc
(or .bashrc
) accordingly.
回答 1
我遇到了同样的问题,这就是我解决的方法:
- 这个问题发生在我身上,因为我是通过pip以普通用户(不是root)的身份安装virtualenv的。pip将软件包安装到目录中
~/.local/lib/pythonX.X/site-packages
- 当我以root用户或具有管理员权限(sudo)运行pip时,它在中安装了软件包
/usr/lib/pythonX.X/dist-packages
。对于您来说,此路径可能有所不同。
- 只在第二种情况下才能识别virtualenv命令
- 因此,要解决此问题,请执行
pip uninstall virtualenv
然后重新安装sudo pip install virtualenv
(或以root身份安装)
I faced the same issue and this is how I solved it:
- The issue occurred to me because I installed virtualenv via pip as a regular user (not root). pip installed the packages into the directory
~/.local/lib/pythonX.X/site-packages
- When I ran pip as root or with admin privileges (sudo), it installed packages in
/usr/lib/pythonX.X/dist-packages
. This path might be different for you.
- virtualenv command gets recognized only in the second scenario
- So, to solve the issue, do
pip uninstall virtualenv
and then reinstall it with sudo pip install virtualenv
(or install as root)
回答 2
最简单的答案。只是:
pip uninstall virtualenv
然后:
pip install virtualenv
或者sudo
,在这种情况下,您可能使用来安装了virtualenv :
pip install --user virtualenv
The simplest answer. Just:
pip uninstall virtualenv
and then:
pip install virtualenv
Or you maybe installed virtualenv with sudo
, in that case:
pip install --user virtualenv
回答 3
在Ubuntu 18.04 LTS上,我也遇到了相同的错误。以下命令有效:
sudo apt-get install python-virtualenv
On Ubuntu 18.04 LTS I also faced same error.
Following command worked:
sudo apt-get install python-virtualenv
回答 4
我在Mac OS X El Capitan上也遇到了同样的问题。
当我这样安装时virtualenv
,sudo pip3 install virtualenv
我没有virtualenv
在命令行下。
我按照以下步骤解决了这个问题:
- 卸载以前的安装。
- 在
virtualenv
安装前通过调用切换到超级用户帐户sudo su
virtualenv
通过调用安装pip3 install virtualenv
- 最后,您应该可以
virtualenv
同时从user
和super user
帐户访问。
I had same problem on Mac OS X El Capitan.
When I installed virtualenv
like that sudo pip3 install virtualenv
I didn’t have virtualenv
under my command line.
I solved this problem by following those steps:
- Uninstall previous installations.
- Switch to super user account prior to
virtualenv
installation by calling sudo su
- Install
virtualenv
by calling pip3 install virtualenv
- Finally you should be able to access
virtualenv
from both user
and super user
account.
回答 5
找出问题
尝试使用--verbose
标志进行安装
pip install virtualenv --verbose
输出看起来像这样
..
Using cached virtualenv-15.1.0-py2.py3-none-any.whl
Downloading from URL https://pypi.python.org/packages/6f/86/3dc328ee7b1a6419ebfac7896d882fba83c48e3561d22ddddf38294d3e83/virtualenv-15.1.0-py2.py3-none-any.whl#md5=aa7e5b86cc8cdb99794c4b99e8d670f3 (from https://pypi.python.org/simple/virtualenv/)
Installing collected packages: virtualenv
changing mode of /home/manos/.local/bin/virtualenv to 755
Successfully installed virtualenv-15.1.0
Cleaning up...
从输出中我们可以看到它已安装在,/home/manos/.local/bin/virtualenv
因此我们确保PATH包含该文件。
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
以我为例,我们可以清楚地看到它/home/manos/.local/bin
完全丢失了,这就是为什么Shell无法找到程序的原因。
解决方案
我们可以通过多种方式解决此问题:
- 我们可以通过点子选项直接安装到特定目录(不推荐)。
- 在
/usr/local/bin
或类似位置创建适当的符号链接。
- 附加
/home/manos/.local/bin
到PATH。
- 以sudo的形式安装以直接安装到
/usr/local/bin
最后两个选项可能是最明智的。最后一个解决方案是最简单的,因此我将仅介绍解决方案3。
将此添加到〜/ .profile:
PATH="$PATH:$HOME/.local/bin"
注销并再次登录,它应该可以工作。
Figure out the problem
Try installing with the --verbose
flag
pip install virtualenv --verbose
Output will look something like this
..
Using cached virtualenv-15.1.0-py2.py3-none-any.whl
Downloading from URL https://pypi.python.org/packages/6f/86/3dc328ee7b1a6419ebfac7896d882fba83c48e3561d22ddddf38294d3e83/virtualenv-15.1.0-py2.py3-none-any.whl#md5=aa7e5b86cc8cdb99794c4b99e8d670f3 (from https://pypi.python.org/simple/virtualenv/)
Installing collected packages: virtualenv
changing mode of /home/manos/.local/bin/virtualenv to 755
Successfully installed virtualenv-15.1.0
Cleaning up...
From the output we can see that it’s installed at /home/manos/.local/bin/virtualenv
so let’s ensure PATH includes that.
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
In my case we can clearly see that /home/manos/.local/bin
is totally missing and that’s why the shell can’t find the program.
Solutions
We can solve this in many ways:
- We can install directly to a specific directory by fiddling with pip options (not recomended).
- Create appropriate symlinks at
/usr/local/bin
or similar.
- Append
/home/manos/.local/bin
to PATH.
- Install as sudo to install directly to
/usr/local/bin
The two last options are probably the most sensible. The last solution is the simplest so therefore I will just show solution 3.
Add this to ~/.profile:
PATH="$PATH:$HOME/.local/bin"
Logout out and in again and it should work.
回答 6
python3 -m virtualenv virtualenv_name
python -m virtualenv virtualenv_name
python3 -m virtualenv virtualenv_name
python -m virtualenv virtualenv_name
回答 7
就我而言,我跑来pip show virtualenv
获取有关virtualenv软件包的信息。我将看起来与此相似,还将显示软件包的位置:
user@machine:~$ pip show virtualenv
Name: virtualenv
Version: 16.2.0
Summary: Virtual Python Environment builder
Home-page: https://virtualenv.pypa.io/
Author: Ian Bicking
Author-email: ianb@colorstudy.com
License: MIT
Location: /home/user/.local/lib/python3.6/site-packages
Requires: setuptools
从那个位置抓取到该位置的.local
一部分,在这种情况下为/home/user/.local/
。您可以在下找到virtualenv命令/home/user/.local/bin/virtualenv
。
然后,您可以运行命令/home/user/.local/bin/virtualenv newvirtualenv
。
In my case, I ran pip show virtualenv
to get the information about virtualenv package. I will look similar to this and will also show location of the package:
user@machine:~$ pip show virtualenv
Name: virtualenv
Version: 16.2.0
Summary: Virtual Python Environment builder
Home-page: https://virtualenv.pypa.io/
Author: Ian Bicking
Author-email: ianb@colorstudy.com
License: MIT
Location: /home/user/.local/lib/python3.6/site-packages
Requires: setuptools
From that grab the part of location up to the .local
part, which in this case is /home/user/.local/
. You can find virtualenv command under /home/user/.local/bin/virtualenv
.
You can then run commands like /home/user/.local/bin/virtualenv newvirtualenv
.
回答 8
我遇到过同样的问题。我使用以下步骤使其工作
sudo pip uninstall virtualenv
sudo -H pip install virtualenv
这就对了。它开始工作了。
sudo -H
—-> sudo -H:
将HOME
变量设置为目标用户主目录的用法。
I had the same issue. I used the following steps to make it work
sudo pip uninstall virtualenv
sudo -H pip install virtualenv
That is it. It started working.
Usage of sudo -H
—-> sudo -H:
set HOME
variable to target user’s home dir.
回答 9
您说过,每次运行pip install
都会得到回报Requirement already satisfied (use --upgrade to upgrade): virtualenv in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
。您需要执行以下操作:
- 更改目录(转到其中virtualenv.py的目录)
cd /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
- 如果您执行了一个操作,
ls
您将看到脚本在那里virtualenv.py
- 像这样运行脚本:
python virtualenv.py --distribute /the/path/at/which/you/want/the/new/venv/at theNameOfTheNewVirtualEnv
希望这可以帮助。我的建议是研究更多静脉。这是一个很好的资源:https : //www.dabapps.com/blog/introduction-to-pip-and-virtualenv-python/
You said that every time you run the pip install
you get Requirement already satisfied (use --upgrade to upgrade): virtualenv in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
. What you need to do is the following:
- Change Directory (go to to the one where the virtualenv.py)
cd /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
- If you do an
ls
you will see that the script is there virtualenv.py
- Run the script like this:
python virtualenv.py --distribute /the/path/at/which/you/want/the/new/venv/at theNameOfTheNewVirtualEnv
Hope this helps. My advice would be to research venvs more. Here is a good resource: https://www.dabapps.com/blog/introduction-to-pip-and-virtualenv-python/
回答 10
我遇到了麻烦,因为我习惯于安装python-virtualenv软件包。要使其正常工作,我必须使用删除该软件包apt-get remove python-virtualenv
并使用进行安装pip install virtualenv
。
I had troubles because I used apt to install python-virtualenv package.
To get it working I had to remove this package with apt-get remove python-virtualenv
and install it with pip install virtualenv
.
回答 11
确保该virtualenv
可执行文件。
如果virtualenv
未找到,/usr/local/bin/virtualenv
则应运行完整路径()。
Ensure that virtualenv
is executable.
If virtualenv
is not found, running the full path (/usr/local/bin/virtualenv
) should work.
回答 12
我认为可以使用简单的符号链接来解决您的问题,但是您正在创建指向错误文件的符号链接。据我所知virtualenv已安装到/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv
,(您可以更改Python版本的数字),因此用于创建符号链接的命令应为:
ln -s /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv /usr/local/bin/virtualenv
I think your problem can be solved using a simple symbolic link, but you are creating the symbolic link to the wrong file. As far as I know virtualenv is installed to /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv
, (you can change the numbers for your Python version) so the command for creating the symbolic link should be:
ln -s /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv /usr/local/bin/virtualenv
回答 13
在ubuntu 18.4上,使用pip的AWS安装无法正常工作。使用apt-get install为我解决了问题。
sudo apt-get install python-virtualenv
并检查
virtualenv --version
On ubuntu 18.4 on AWS installation with pip don’t work correctly.
Using apt-get install the problem was solved for me.
sudo apt-get install python-virtualenv
and to check
virtualenv --version
回答 14
回答 15
如果您使用的是Linux,请打开您的终端,然后在其中途键入virtualenv,然后使用Tab键自动完成。如果没有自动完成功能,请运行以下命令在系统上安装virtualenv:
mycomp$sudo apt-get install virtualenv
//if you're already super user.
mycomp#apt-get install virtualenv
现在,您可以导航到要创建项目的位置并执行以下操作:
myprj$pip3 install virtualenv
//to install python 3.5 and above
myprj$virtualenv venv --python=python3.5
//to activate virtualenv
(venv)myprj$source venv/bin/activate
(venv)myprj$deactivate
If you’re using Linux, open your terminal and type virtualenv halfway and autocomplete with tab key. If there’s no auto-completion install virtualenv on your system by running:
mycomp$sudo apt-get install virtualenv
//if you're already super user.
mycomp#apt-get install virtualenv
You can now navigate to where you want to create your project and do:
myprj$pip3 install virtualenv
//to install python 3.5 and above
myprj$virtualenv venv --python=python3.5
//to activate virtualenv
(venv)myprj$source venv/bin/activate
(venv)myprj$deactivate
回答 16
这在ubuntu 18及更高版本中有效(未经先前版本测试):
sudo apt install python3-virtualenv
this works in ubuntu 18 and above (not tested in previous versions):
sudo apt install python3-virtualenv
回答 17
请按照以下基本步骤设置虚拟环境
sudo pip install virtualenv virtualenvwrapper
sudo rm -rf ~/get-pip.py ~/.cache/pip
我们需要更新我们的 ~/.bashrc
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
该~/.bashrc
文件只是Shell脚本,只要您启动新终端,Bash就会运行。通常,您使用此文件来设置各种配置。在这种情况下,我们将设置一个名为的环境变量,WORKON_HOME
以指向我们的Python虚拟环境所在的目录。然后,我们从virtualenvwrapper加载任何必要的配置。
要更新~/.bashrc
文件,只需使用标准的文本编辑器,nano可能是最容易操作的。一个更简单的解决方案是使用cat命令并完全避免使用编辑器:
echo -e "\n# virtualenv and virtualenvwrapper" >> ~/.bashrc
echo "export WORKON_HOME=$HOME/.virtualenvs" >> ~/.bashrc
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
编辑〜/ .bashrc文件后,我们需要重新加载更改:
source ~/.bashrc
现在我们已经安装了virtualenv和virtualenvwrapper,下一步是实际创建Python虚拟环境-我们使用mkvirtualenv命令执行此操作。
mkvirtualenv YOURENV
Follow these basic steps to setup the virtual env
sudo pip install virtualenv virtualenvwrapper
sudo rm -rf ~/get-pip.py ~/.cache/pip
we need to update our ~/.bashrc
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
The ~/.bashrc
file is simply a shell script that Bash runs whenever you launch a new terminal. You normally use this file to set various configurations. In this case, we are setting an environment variable called WORKON_HOME
to point to the directory where our Python virtual environments live. We then load any necessary configurations from virtualenvwrapper .
To update your ~/.bashrc
file simply use a standard text editor, nano is likely the easiest to operate.
A more simple solution is to use the cat command and avoid editors entirely:
echo -e "\n# virtualenv and virtualenvwrapper" >> ~/.bashrc
echo "export WORKON_HOME=$HOME/.virtualenvs" >> ~/.bashrc
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
After editing our ~/.bashrc file, we need to reload the changes:
source ~/.bashrc
Now that we have installed virtualenv and virtualenvwrapper , the next step is to actually create the Python virtual environment — we do this using the mkvirtualenv command.
mkvirtualenv YOURENV
回答 18
对我来说,它已安装在以下路径中(在MacOS上为python 2.7):$ HOME / Library / Python / 2.7 / bin
For me it was installed in this path (python 2.7 on MacOS):
$HOME/Library/Python/2.7/bin
回答 19
我正在做Angela Yu的在线iOS类,遇到同样的问题,当我尝试运行时也遇到权限被拒绝的错误13 virtualenv --python=/{myPath} {newVirtualEnvName}
我通过以下方法解决了它:
- 切换到sudo用户
sudo su
- 导航到我的目标文件夹(我希望我的新虚拟环境驻留在其中),即。/ Users / muUserName / Environments /
- 运行命令
python -m virtualenv python27
,其中python27是我的新的虚拟环境的名称
- 上面在我的环境文件夹中创建了文件夹pathon27,然后我能够运行以启动我的virtualenv
source python27/bin/activate
I’m doing Angela Yu’s online iOS course and I was getting same problem plus also was getting permission denied error 13 when I was trying to run virtualenv --python=/{myPath} {newVirtualEnvName}
I solved it by:
- switching to sudo user
sudo su
- navigating to my destination folder (where I want my new virtual env to live) ie. /Users/muUserName/Environments/
- run command
python -m virtualenv python27
where python27 is a name of my new virtual environment
- above created folder pathon27 in my Environments folder, and then I was able to run
source python27/bin/activate
to start my virtualenv
回答 20
简单的答案是,如果您不是我(不是我)的sudo用户,则需要添加bin文件夹(/home/myusername/.local/bin
)的路径。因此基本上,命令行会在您键入这些命令的路径中搜索哪个。
export PATH=/home/b18150/.local/bin:/usr/bin:/bin
在这里它将先搜索local/bin
然后/usr/bin
再搜索/bin
。
Simple answer is that if you are not a sudo user as I was not one.You need to add path of your bin folder (/home/myusername/.local/bin
).So basically the command line searches in which of these path is the command which you have typed.
export PATH=/home/b18150/.local/bin:/usr/bin:/bin
here it will search in local/bin
first then /usr/bin
and then /bin
.
回答 21
我有相同的问题很长时间了。我通过运行以下两个命令解决了这个问题,首先是安装,其次是激活env:
python3 -m pip install virtualenv
python3 -m virtualenv yourenvname
请注意,我使用python3
,你可以把它改成只是python
如果python3
失败。谢谢。
I had the same problem for a long time.
I solved it by running these two commands, first is to install second is to activate the env:
python3 -m pip install virtualenv
python3 -m virtualenv yourenvname
Note that I’m using python3
, you can change it to just python
if python3
fails.
Thanks.
回答 22
apt update
apt upgrade
apt install ufw python virtualenv git unzip pv
3个命令,一切正常!
apt update
apt upgrade
apt install ufw python virtualenv git unzip pv
3 commands and everything working!
回答 23
sudo apt-get install python-virtualenv
sudo apt-get install python-virtualenv