问题:找不到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

我遇到了同样的问题,这就是我解决的方法:

  1. 这个问题发生在我身上,因为我是通过pip以普通用户(不是root)的身份安装virtualenv的。pip将软件包安装到目录中~/.local/lib/pythonX.X/site-packages
  2. 当我以root用户或具有管理员权限(sudo)运行pip时,它在中安装了软件包/usr/lib/pythonX.X/dist-packages。对于您来说,此路径可能有所不同。
  3. 只在第二种情况下才能识别virtualenv命令
  4. 因此,要解决此问题,请执行pip uninstall virtualenv然后重新安装sudo pip install virtualenv(或以root身份安装)

I faced the same issue and this is how I solved it:

  1. 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
  2. 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.
  3. virtualenv command gets recognized only in the second scenario
  4. 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上也遇到了同样的问题。

当我这样安装时virtualenvsudo pip3 install virtualenv我没有virtualenv在命令行下。

我按照以下步骤解决了这个问题:

  1. 卸载以前的安装。
  2. virtualenv安装前通过调用切换到超级用户帐户sudo su
  3. virtualenv通过调用安装pip3 install virtualenv
  4. 最后,您应该可以virtualenv同时从usersuper 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:

  1. Uninstall previous installations.
  2. Switch to super user account prior to virtualenv installation by calling sudo su
  3. Install virtualenv by calling pip3 install virtualenv
  4. 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无法找到程序的原因。

解决方案

我们可以通过多种方式解决此问题:

  1. 我们可以通过点子选项直接安装到特定目录(不推荐)。
  2. /usr/local/bin或类似位置创建适当的符号链接。
  3. 附加/home/manos/.local/bin到PATH。
  4. 以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:

  1. We can install directly to a specific directory by fiddling with pip options (not recomended).
  2. Create appropriate symlinks at /usr/local/bin or similar.
  3. Append /home/manos/.local/bin to PATH.
  4. 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。您需要执行以下操作:

  1. 更改目录(转到其中virtualenv.py的目录) cd /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
  2. 如果您执行了一个操作,ls您将看到脚本在那里virtualenv.py
  3. 像这样运行脚本: 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:

  1. Change Directory (go to to the one where the virtualenv.py) cd /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
  2. If you do an ls you will see that the script is there virtualenv.py
  3. 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

同样的问题: 所以,我只是做了pip uninstall virtualenv 那么 pip install virtualenv

pip install virtualenv --user

使用缓存的https://files.pythonhosted.org/packages/b6/30/96a02b2287098b23b875bc8c2f58071c35d2efe84f747b64d523721dc2b5/virtualenv-16.0.0-py2.py3-none-any.whl 安装收集的软件包:virtualenv

然后我得到了:

脚本virtualenv安装在PATH之外的’/Users/brahim/Library/Python/2.7/bin’中。考虑将该目录添加到PATH,或者,如果您不想显示此警告,请使用–no-warn-script-location。

它清楚地说明了它的安装位置以及如何获得它

Same problem: So I just did pip uninstall virtualenv Then pip install virtualenv

pip install virtualenv --user

Collecting virtualenv Using cached https://files.pythonhosted.org/packages/b6/30/96a02b2287098b23b875bc8c2f58071c35d2efe84f747b64d523721dc2b5/virtualenv-16.0.0-py2.py3-none-any.whl Installing collected packages: virtualenv

Then I got this :

The script virtualenv is installed in ‘/Users/brahim/Library/Python/2.7/bin’ which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use –no-warn-script-location.

which clearly says where it is installed and what to do to get it


回答 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}

我通过以下方法解决了它:

  1. 切换到sudo用户 sudo su
  2. 导航到我的目标文件夹(我希望我的新虚拟环境驻留在其中),即。/ Users / muUserName / Environments /
  3. 运行命令python -m virtualenv python27,其中python27是我的新的虚拟环境的名称
  4. 上面在我的环境文件夹中创建了文件夹pathon27,然后我能够运行以启动我的virtualenvsource 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:

  1. switching to sudo user sudo su
  2. navigating to my destination folder (where I want my new virtual env to live) ie. /Users/muUserName/Environments/
  3. run command python -m virtualenv python27 where python27 is a name of my new virtual environment
  4. 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

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。