The error "virtualenv: command not found", but the installation location is in PYTHONPATH

It made me crazy in the last 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 message "virtualenv: command not found".

I used pip show virtualenv and the installation location was "Location: /usr/local/lib/python2.7/site-packages", but I cannot figure out where the executable is located. I have tried dozens of other similar posts, but these solutions do not work for me.

Any ideas what might be wrong here?

+19
python pip
source share
9 answers

The only workable approach I could figure out (using @Gator_Python was to make python -m virtualenv venv . This creates a virtual environment and works as expected.

I have custom python installed and maybe for some reason the default does not work for me.

+48
source share

In macOS Mojave
First check the python along the way.
python --version
The second check is set.
pip --version
If it is not installed.
brew install pip
Third virtualenv installation
sudo -H pip install virtualenv

+7
source share

As mentioned in the comments, you correctly installed the virtualenv module in the expected environment, since python -m venv allows you to create virtualenv.

The fact that virtualenv not a recognized command is the result of virtualenv.py not on your PATH system and / or not executable. The root cause may be obsolete distutils or setuptools.

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

+4
source share

Maybe you're using Anaconda's package manager? If so, then it has its own virtual environment system, which you configure as follows:

 conda create --name venv 
+1
source share

I had the same problem (albeit on ubuntu), a simple solution instead of doing pip install virtualenv , you precede the praise of " sudo ".

A small check shows the reason for this fix: enter image description here

pip install virtualenv tries to put the executable in /usr/local/bin so that it can be called from the command line, but it failed because only root has write permissions to this directory

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

+1
source share

I managed to manually create a link to the location / virtualenv.py file in / usr / local / bin, name it virtualenv and add the + x attribute to the 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: ianb@colorstudy.com 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 
0
source share

I tried to have virtualenv in a random place & ran into the same problem on an UBUNTU machine when I tried to run my 'venv'. What solved my problem was: -

$ virtualenv -p python3 venv

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

0
source share

For python 3

 python3 -m virtualenv venv 
0
source share
  1. Install python package manager.
  2. Install the virtual environment using pip3 install virtualenv or pip install virtualenv.
-one
source share

All Articles