Virtualenv Command Not Found

426,350

Solution 1

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.

Solution 2

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)

Solution 3

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

Solution 4

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

sudo apt-get install python-virtualenv

Solution 5

python3 -m virtualenv virtualenv_name   

or

python -m virtualenv virtualenv_name
Share:
426,350

Related videos on Youtube

Arial
Author by

Arial

Always inspired by products that solve meaningful problems.

Updated on July 16, 2022

Comments

  • Arial
    Arial almost 2 years

    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?

    • Justin Fay
      Justin Fay almost 9 years
      Try adding a symlink to the virtualenv executable in /usr/local/bin
    • Arial
      Arial almost 9 years
      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
    • Justin Fay
      Justin Fay almost 9 years
      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-pac‌​kages/virtualenv/vir‌​tualenv.py
    • Aliza
      Aliza over 8 years
      what worked for me was to add a symlink ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python‌​2.7/site-packages/vi‌​rtualenv.py /usr/local/bin/virtualenv
    • c24b
      c24b over 8 years
      Doesn't work in a lubuntu
    • JulienD
      JulienD about 8 years
      What if you try pip install virtualenv --user ? Also check the permissions of /usr/local/bin/ (you wrote that it was indeed installed in /usr/local/bin/, so if it is not found it looks more like a permissions issue).
    • Ozkan Serttas
      Ozkan Serttas about 4 years
      I tried adding Lazy Loading method to initialize virtualenv. Please see this part in the documentation
  • smudo78
    smudo78 almost 8 years
    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
  • user5359531
    user5359531 almost 8 years
    what if root is not available on your machine?
  • Mariano Kamp
    Mariano Kamp over 7 years
    Did you see that he was asking for Mac OSX?
  • Admin
    Admin over 7 years
    Solved the problem. I guess this one can go into the global dir instead of --user.
  • emrahgunduz
    emrahgunduz over 6 years
    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.
  • Dmitri DB
    Dmitri DB over 6 years
    Which leaves the question: Why the devil is my python3-virtualenv package broken?
  • Kirby
    Kirby over 6 years
    setting up the sym link was all i needed to do. thank you.
  • race_carr
    race_carr about 6 years
    Wow! This is what did the trick for me. I am using pyenv by the way
  • TCSGrad
    TCSGrad almost 6 years
    This is the way to go for Mac OS X using brew.
  • HellaDev
    HellaDev about 5 years
    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!
  • CarmenA
    CarmenA almost 5 years
    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.
  • Leonard
    Leonard over 4 years
    brew install python-virtualenv does not exist
  • Matteo
    Matteo over 4 years
    The question is for mac OS, there is no apt
  • David
    David over 4 years
    This worked perfectly. It should be the accepted answer and +1 for the detailed explanation
  • Ced
    Ced over 4 years
    the output is sudo: /usr/bin/easy_install: command not found
  • Thomas Kimber
    Thomas Kimber over 4 years
    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?
  • Nischaya Sharma
    Nischaya Sharma over 4 years
    Worked like a charm on my 18.04, Thanks
  • manuele
    manuele about 4 years
    It fixes for me exacly the same problem... why it's not checked as the solution?
  • greybeard
    greybeard about 4 years
    Voted down to promote apt as a successor to apt-get.
  • yoon
    yoon almost 4 years
    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.
  • ofer.sheffer
    ofer.sheffer almost 4 years
    worked for me without the 3. python -m virtualenv <name>
  • Peter Wauyo
    Peter Wauyo over 3 years
    This worked for me on MacOs python -m venv venv_name
  • Jose Andres Montes Espinoza
    Jose Andres Montes Espinoza over 3 years
    Also worked for Ubuntu. I was having issues setting it up for digital ocean. This should be the solution.
  • landesko
    landesko about 3 years
    Step 4 was what I was looking for! I couldn't figure out how to get files out of ~/.local
  • DariusL
    DariusL about 3 years
    Always a good method of solving path issues with python.
  • Hansang
    Hansang almost 3 years
    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
  • ultrasounder
    ultrasounder over 2 years
    Followed the above instructions and worked for me. @vettipayyan is not all that Vetti after all
  • Nathan McKaskle
    Nathan McKaskle over 2 years
    This only works most likely if python 3.6+ is the default when using the python command.
  • Nathan McKaskle
    Nathan McKaskle over 2 years
    It keeps trying to use 2.7.
  • Dushan Wijesinghe
    Dushan Wijesinghe over 2 years
    Works for macOS Big Sur 11.6
  • Nube Colectiva
    Nube Colectiva almost 2 years
    worked for me: "python -m virtualenv myvirtualenv" in windwos 10 - 64 bytes.