Error "virtualenv : command not found" but install location is in PYTHONPATH

Question:

This has been driving me crazy for the past 2 days.
I installed virtualenv on my Macbook using pip install virtualenv.
But when I try to create a new virtualenv using virtualenv venv, I get the error saying “virtualenv : command not found”.

I used pip show virtualenv and the location of the installation is “Location: /usr/local/lib/python2.7/site-packages” but I can’t figure out where the executable is. I tried dozens other similar looking posts but those solutions do not work for me.

Any ideas what might be going wrong here?

Asked By: Pravesh Jain

||

Answers:

The only workable approach I could figure out (with help from @Gator_Python was to do python -m virtualenv venv. This creates the virtual environment and works as expected.

I have custom python installed and maybe that’s why the default approach doesn’t work for me.

Answered By: Pravesh Jain

As mentioned in the comments, you’ve got the virtualenv module installed properly in the expected environment since python -m venv allows you to create virtualenv’s.

The fact that virtualenv is not a recognized command is a result of the virtualenv.py not being in your system PATH and/or not being executable. The root cause could be outdated distutils or setuptools.

You should attempt to locate the virtualenv.py file, ensure it is executable (chmod +x) and that its location is in your system PATH. On my system, virtualenv.py is in the ../Pythonx.x/Scripts folder, but this may be different for you.

Answered By: sytech

Could it be that you are using Anaconda package manager? If so, then it has it’s own virtual environment system which you setup as follows:

conda create --name venv
Answered By: Bill

I had the same issue (although on ubuntu), a simple solution is instead of doing pip install virtualenv, you precede the commend with "sudo".

A little inspection reveals the reason behind this fix:
enter image description here

pip install virtualenv tries to put an executable under /usr/local/bin so that it can be invoked from command line, but it failed because only root has write permission to that directory

an alternative is pip install --user virtualenv, here are some further readings 1,2

Answered By: watashiSHUN

On macOS Mojave
First check python is in the path.
python --version
Second check pip is installed.
pip --version
If it is not installed.
brew install pip
Third install virtualenv
sudo -H pip install virtualenv

Answered By: Mian Asbat Ahmad

I succeded creating manually a link to location/virtualenv.py in /usr/local/bin, naming it virtualenv and adding +x attribute on file

➜  ~ pip show virtualenv
Name: virtualenv
Version: 16.6.0
Summary: Virtual Python Environment builder
Home-page: https://virtualenv.pypa.io/
Author: Ian Bicking
Author-email: [email protected]
License: MIT
Location: /home/prsadev/.local/lib/python2.7/site-packages
Requires: 


~ chmod +x /home/prsadev/.local/lib/python2.7/site-packages/virtualenv.py 
~ sudo ln -sf /home/prsadev/.local/lib/python2.7/site-packages/virtualenv.py /usr/local/bin/virtualenv
Answered By: Damien Ferey

I tried to have virtualenv at a random location & faced the same issue on a UBUNTU machine, when I tried to run my ‘venv’. What solved my issue was :-

$virtualenv -p python3 venv

Also,instead of using $activate try :-
$source activate
If you look at the activate script(or $cat activate), you will find the same in comment.

Answered By: Amit Prajapati

For Python 3

python3 -m virtualenv venv
Answered By: Lal Krishna

Had the same problem on Windows. Command not found and can’t find the executable in the directory given by pip show.

Fixed it by adding "C:Users{My User}AppDataRoamingPythonPython39Scripts" to the PATH environment variable.

Answered By: Eric Pedley

Install virtualenv from https://pypi.org/project/virtualenv

python -m pip install –user virtualenv

sudo /usr/bin/easy_install virtualenv

This solved my similar problem!

You need to look online on how to create a virtual environement with python X.X.X (replace x.x.x with your python version)

mine was python 3.4.3 so bellow is how should i deal with it:

sudo python3 -m venv aramisvenv
Answered By: Aramis NSR

I use asdf and had to do a reshim after installing virtualenv. asdf reshim

Fixed due to this response

Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.