372

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?

Nathaniel Ford
21.3k20 gold badges98 silver badges112 bronze badges
asked Jun 30, 2015 at 8:17
7
  • 1
    Try adding a symlink to the virtualenv executable in /usr/local/bin Commented Jun 30, 2015 at 8:33
  • Where should I create the symlink? It's still not working despite I tried to add a symlink at the directory where I want to use virtualenv @justinfay Commented Jul 1, 2015 at 2:59
  • 2
    from looking at the paths above it could be something like, replace the last path in the command with the path to the actual virtualenv executable: $ ln -s /usr/bin/virtualenv /Library/Framework/Python.framework/Version/2.7/lib/site-packages/virtualenv/virtualenv.py Commented Jul 1, 2015 at 11:16
  • 4
    what worked for me was to add a symlink ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.py /usr/local/bin/virtualenv Commented Jan 24, 2016 at 14:51
  • Doesn't work in a lubuntu Commented Feb 15, 2016 at 16:53

32 Answers 32

1
2
439

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.

Piper
1,2673 gold badges15 silver badges26 bronze badges
answered Jan 2, 2017 at 15:09
Sign up to request clarification or add additional context in comments.

7 Comments

on AWS EC2 instance with Amazon Linux, if you are trying Let's Encrypt's certbot, give this solution a try. This was the only suggestion that solved my virtualenv problem.
the output is sudo: /usr/bin/easy_install: command not found
Thankyou for this - but I wish I knew what witchcraft is at work here - what does "easy_install" do that regular pip doesn't do? i.e. Why does this work?
This worked for me on MacOs python -m venv venv_name
It keeps trying to use 2.7.
|
317

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)
answered May 15, 2016 at 19:05

10 Comments

I followed your solution and got the message "...If executing pip with sudo, you may want sudo's -H flag". Finally sudo -H pip install virtualenv did the job for me (on OS X), thank you
what if root is not available on your machine?
Solved the problem. I guess this one can go into the global dir instead of --user.
This issue also happens when pip itself is installed in ~/.local/SOME_PATH. I cp ed everything in site-packages dir into /usr/lib/pythonx.x/site-packages, and rm -rfed the original directory.
Step 4 was what I was looking for! I couldn't figure out how to get files out of ~/.local
|
91

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
answered Jan 4, 2018 at 3:27

5 Comments

Wow! This is what did the trick for me. I am using pyenv by the way
This is the way to go for Mac OS X using brew.
Been fighting this for weeks and it has been hindering my limited time to work on a python project and this was the only solution to work for me on mac. Thank you!
Thank you, using Sudo after uninstalling the previous version worked for me: ``` pip uninstall virtualenv sudo pip install virtualenv ```
Thanks! Worked like a charm on Mac with M1 silicon!
85
python3 -m virtualenv virtualenv_name 

or

python -m virtualenv virtualenv_name
vvvvv
32.9k19 gold badges70 silver badges103 bronze badges
answered Aug 20, 2019 at 6:29

3 Comments

worked for me without the 3. python -m virtualenv <name>
Always a good method of solving path issues with python.
worked for me: "python -m virtualenv myvirtualenv" in windwos 10 - 64 bytes.
52

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.

J. Scott Elblein
4,36316 gold badges65 silver badges106 bronze badges
answered Jan 25, 2020 at 0:24

2 Comments

It fixes for me exacly the same problem... why it's not checked as the solution?
Also worked for Ubuntu. I was having issues setting it up for digital ocean. This should be the solution.
46

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.
answered Dec 13, 2016 at 7:29

4 Comments

Works for macOS Big Sur 11.6
Works for macOS Ventura 13.3
Works for macOS Monterey 12.7.4
Worked on macOS Sonoma 14.4.1
46

On Ubuntu 18.04 LTS I also faced same error. Following command worked:

sudo apt-get install python-virtualenv
answered May 11, 2018 at 16:00

2 Comments

brew install python-virtualenv does not exist
Voted down to promote apt as a successor to apt-get.
22

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.

answered May 27, 2017 at 22:13

1 Comment

This worked perfectly. It should be the accepted answer and +1 for the detailed explanation
20

Found this solution and this worked perfectly for me.

sudo -H pip install virtualenv

The -H sets it to the HOME directory, which seems to be the issue for most people.

user3151675
58.4k29 gold badges187 silver badges240 bronze badges
answered Oct 4, 2020 at 11:25

Comments

16

You are having this error :

zsh: command not found: virtualenv

Because most probably you tried to install virtualenv without typing sudo beforehand.

If you try to add it to /usr/local/bin, this may result on syntax errors as the packages are not properly isntalled/copied:

SyntaxError: invalid syntax
 File "build/bdist.macosx-12.0-x86_64/egg/platformdirs/__main__.py", line 16
 def main() -> None:
 ^

In case you have tried to install virtualenv via pip without sudo rights, you need first to uninstall it:

pip3 uninstall virtualenv

Then install it using sudo:

sudo pip3 install virtualenv

Next you just need to activate the env:

virtualenv env 
source env/bin/activate 
answered Dec 23, 2021 at 5:32

Comments

15

Personally. I did the same steps you did on a fresh Ubuntu 20 installation (except that I used pip3). I got the same problem, and I remember I solved it this way:

python3 -m virtualenv venv 

Link to understand the -m <module-name> notation.

answered Aug 19, 2020 at 10:54

Comments

12

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: [email protected]
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.

answered Jan 18, 2019 at 12:08

Comments

11

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/

answered Apr 12, 2016 at 15:04

Comments

9

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.

avpaderno
30k17 gold badges81 silver badges95 bronze badges
answered Jun 9, 2017 at 9:36

1 Comment

Which leaves the question: Why the devil is my python3-virtualenv package broken?
7

Ensure that virtualenv is executable.

If virtualenv is not found, running the full path (/usr/local/bin/virtualenv) should work.

answered Apr 3, 2016 at 4:12

Comments

7

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.

answered Jun 13, 2020 at 15:02

Comments

6

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
answered Jun 8, 2017 at 22:33

1 Comment

setting up the sym link was all i needed to do. thank you.
6

This works on Ubuntu 18 and above (not tested in previous versions):

sudo apt install python3-virtualenv
vvvvv
32.9k19 gold badges70 silver badges103 bronze badges
answered Apr 28, 2020 at 7:45

1 Comment

I confirm it worked on Ubuntu 20.04
5

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
answered Jan 11, 2019 at 15:22

Comments

5

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:

sudo apt-get install virtualenv
# if you're already super user.
apt-get install virtualenv

You can now navigate to where you want to create your project and do:

pip3 install virtualenv 
# to install python 3.5 and above 
virtualenv venv --python=python3.5 
# to activate virtualenv 
source venv/bin/activate 
# to desactivate virtualenv
(venv)deactivate
Juanma
7281 gold badge8 silver badges22 bronze badges
answered Oct 8, 2018 at 12:24

1 Comment

I upgraded to python 3.7. I kept trying to install virtualenv, it will always return "Error: Could not find a version that satisfies the requirement virtualenv (from versions: none)". I read somewhere that from a certain python 3.x version it comes with virtualenv installed, but trying to create a virtual environment simple, didn't work, it would return error that it doesn't know the virtualenv command. But it worked with the following command from your answer, "virtualenv venv --python=python3.7". Nothing else done prior. In case it helps anyone else. MacOS environment.
4

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

answered Sep 12, 2018 at 23:56

Comments

2

Make sure that you are using

sudo

In this case, at first you need to uninstall the pipenv and then install again using sudo command.

  1. pip uninstall pipenv
  2. sudo pip install pipenv
answered Feb 23, 2021 at 9:03

Comments

2

If you installed it with

pip install virtualenv

Now to use it you need to type this command:

python -m virtualenv name_of_your_virtualenv

in order to activate it:

.\name_of_your_virtualenv\Scripts\activate

if you face a problem activating your virtualenv, it could be Execution Policy Settings. To fix it, you should try executing this command in your command line: Set-ExecutionPolicy Unrestricted -Scope Process. This would allow PowerShell will run the script.

answered Oct 15, 2022 at 21:15

1 Comment

No need to go for other commands, just install the virtualenv as root user privilege. like this: sudo pip install virtualenv
1

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
Yuyutsu
2,52724 silver badges38 bronze badges
answered Oct 5, 2017 at 6:49

Comments

1

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
answered Apr 28, 2020 at 3:54

1 Comment

switching to sudo su worked for me, even though i wanted to use python3 as the venv folder to be created. It seems that it's a permissions issue when trying to install locally and the elevated sudo not finding the correct path unless explicitly logged in as root
1

on Mac

> pip3 install virtualenv
> python3 -m virtualenv [venv_name_you_want]

Q. virtualenv not found
After installing virtualenv, virtualenv exist on the pip3 list. But When to use the "virtualenv [venv_name]" command, it returns "virtualenv not found".

A. Because virtualenv is installed as a module in python3. Not installed as a command tool like python3 in the "/usr/bin/.." path. So this case we can use "python3 -m virtualenv [venv_name]".

And we can see where it is to retry this command "pip3 install virtualenv". Then zsh or your shell tells us kindly this info.

Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: virtualenv in /Users/[your-usr-name-here]/Library/Python/3.8/lib/python/site-packages (20.16.5) Requirement already satisfied: filelock<4,>=3.4.1 in /Users/[your-usr-name-here]/Library/Python/3.8/lib/python/site-packages (from virtualenv) (3.8.0) ...

answered Sep 11, 2022 at 2:25

Comments

1

After upgrading MacOS Monterey from 12.5.1 to 12.6, I was no longer able to run virtualenv. Since I had brew on my mac, installed like this:

$ brew install virtualenv
...
==> Installing virtualenv
==> Pouring virtualenv--20.16.5.monterey.bottle.tar.gz
 /usr/local/Cellar/virtualenv/20.16.5: 949 files, 20.3MB
==> Running `brew cleanup virtualenv`...
...

Of course, brew decided to upgrade various other packages I had as well, but virtualenv was available again thereafter.

answered Sep 19, 2022 at 2:30

Comments

0

For me it was installed in this path (python 2.7 on MacOS): $HOME/Library/Python/2.7/bin

answered Nov 20, 2019 at 12:49

Comments

0

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.

Arghya Sadhu
45.2k10 gold badges100 silver badges123 bronze badges
answered Jun 13, 2020 at 11:59

Comments

0

Following steps worked for me on Ubuntu 22.04

pip3 install virtualenv
sudo apt install python3.10-venv
python -m venv <name of virtual env>
source <path to Virtual env folder/bin/activate>
answered Aug 1, 2023 at 11:53

Comments

1
2

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.