virtualenvwrapper commands aren't working
Asked Answered
H

7

67
tow-81-235:Projects pessimisticoptimism$ mkvirtualenv development
-bash: mkvirtualenv: command not found
tow-81-235:Projects pessimisticoptimism$ sudo pip install virtualenvwrapper
Password:
Requirement already satisfied (use --upgrade to upgrade): virtualenvwrapper in /Library/Python/2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): virtualenv in /Library/Python/2.7/site-packages (from virtualenvwrapper)
Requirement already satisfied (use --upgrade to upgrade): virtualenv-clone in /Library/Python/2.7/site-packages (from virtualenvwrapper)
Cleaning up...
tow-81-235:Projects pessimisticoptimism$ mkvirtualenv development
-bash: mkvirtualenv: command not found

Why am I getting this error? I have virtualenv and virtualenvwrapper installed. I'd like to use mkvirtualenv and workon. I find it odd that virtualenv is working, but virtualenvwrapper isn't.

Hawserlaid answered 2/9, 2012 at 0:14 Comment(0)
P
185

1st, ensure you're installing with sudo:

sudo pip install virtualenvwrapper

2nd, append the following lines to your .bashrc file (with nano ~/.bashrc):

export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

3rd, reload your profile

source ~/.bashrc
Pushy answered 6/12, 2012 at 4:28 Comment(8)
Worked for me..! thnxMitchiner
After i close my teminal. When i open again the workon command doesn't work.. it occurs 'command not found' is there any way to be permanent active? so i can to do 'source .venvs/app/bin/activate' every time i open my terminal ??Starla
Hi @ePascoal, the lines in the .bashrc are supposed to make it the changes permanent. Every time you launch a terminal it reads the current user's .bashrc (assuming you are using bash as your shell). You should be able to add workon app under the 3rd line (`source ...) in your .bashrc to make it automatically activate each time.Pushy
MAC USERS - Use .bash_profile instead of .bashrc like Will's answer suggests.Turman
To make it permanent, make sure you are adding the two lines (export... and source...) to your ~/.bahrc file, and not only copying and pasting the commands in the terminal!Tremml
seems this issue is very common. Why don't authors of virtualenv fix it for permanent?Ruano
Hi @KishorPawar, virtualenvwrapper is a standard shell script. The reason for adding it to .bashrc is so that it can create the virtual environment mappings (i.e. mkvirtualenv) every time you open the terminal without having to call the script yourself every time.Pushy
That is what my question is, why can't these lines be added to .bashrc during installation only?Ruano
E
37

Summary

I'm on a Mac and my answer is similar to @Ramces answer except it was with bash_profile. I just want to elaborate a little further for Mac users to be aware that there's a lot of different profiles including:

  • .bashrc
  • .bash_profile
  • .profile

Some files like .profile do not take precedence over .bash_profile (if it exists) and will then be ignored. If you successfully do the below steps and get a virtual env working, but then close out your terminal and 'workon command not found', then you need to setup for the correct profile. For a detailed answer, see here

Install Steps:

  1. sudo pip install virtualenv

    Installs virtualenv (allows you to separate your envrionments)

  2. sudo pip install virtualenvwrapper

    Installs virtualenvwrapper (allows you to use the 'workon' command)

  3. nano ~/.bash_profile

    export WORKON_HOME=$HOME/.virtualenvs
    source /usr/local/bin/virtualenvwrapper.sh
    
  4. source ~/.bash_profile

    Reloads the profile. Going forward you only need step 5 (to create new environments) and step 6 (to run environments)

  5. mkvirtualenv my_env

    This creates your virtual environment (this example is with 'my_env')

  6. workon my_env

    This lets you work on a specific environment (this example is with 'my_env')

Evincive answered 13/5, 2014 at 14:29 Comment(2)
I want to run workon my_env with sudo. sudo workon my_env says workon: command not found. How do I fix this?Grandsire
Hi, i have a problem that my virtualenvwrpper.sh doesnt exist in /usr/local/bin/ it exists in /Library/Frameworks/Python.framework/Versions/3.8/bin/virtualenvwrapper.$Aponeurosis
C
10

After installing the virtualenvwrapper package using pip, you also have to do some initialisation/set your preferences. See the introduction in the virtualenvwrapper docs.

Most relevant for finding the commands should be sourcing the virtualenvwrapper script into your shell. In the docs it is mentioned as

$ source /usr/local/bin/virtualenvwrapper.sh

You still have to adjust the path to your setup. My guess for your Mac would be:

$ source /Library/Python/2.7/site-packages/virtualenvwrapper.sh
Chirpy answered 2/9, 2012 at 2:1 Comment(1)
If you are already in the virtual environment, the virtualenvwrapper.sh is in the bin folder of that virtual environment itself like below { source ~/mypythonenv/bin/virtualenvwrapper.sh }Arel
D
9

Simple process

  1. sudo apt-get install python-pip(if pip is not installed)
  2. sudo pip install virtualenv
  3. Create a dir to store your virtualenvs

    mkdir ~/.virtualenvs

  4. sudo pip install virtualenvwrapper

  5. Run following command

    export WORKON_HOME=~/.virtualenvs

  6. Add virtualenvwrapper.sh to .bashrc Add this line to the end of ~/.bashrc so that the virtualenvwrapper commands are loaded.

    . /usr/local/bin/virtualenvwrapper.sh

  7. you will find .bashrc.sh file in home directory by doing ctrl+h. if not then use find command to find .bashrc.sh "file ls -la ~/ | more"

  8. Hit this command

    source /usr/local/bin/virtualenvwrapper.sh

  9. Hit this command

    source ~/.bashrc

Dope answered 25/6, 2015 at 12:58 Comment(0)
G
4

It sounds like you have multiple Python installations on your machine and virtualenvwrapper is not pointing to the right Python.

Find out which Python virtualenvwrapper is using. You get a hint where to look with which virtualenvwrapper.sh (In this case /usr/local/bin):

> /usr/local/bin/virtualenvwrapper.sh

If you don't get any return here make sure you use the correct pip when installing. The pip command might link to a different Python then you expect. Check your usr/local/bin directory for pip links (pip, pip2, pip2.7, pip3, pip3.5). It is easy to get system pip, pip2 and pip2.7 mixed up.

After you have found the Python location, add/update all paths in your .profile:

export WORKON_HOME=$HOME/venv
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2
source /usr/local/bin/virtualenvwrapper.sh

Finally reload your profile: source ~/.profile

Galina answered 30/10, 2017 at 4:3 Comment(2)
Why you are using $HOME/Envs and not $HOME/venv? Also I get the error: /Library/Frameworks/Python.framework/Versions/3.7/bin/virtualenvwrapper.sh: fork: Resource temporarily unavailable Any clue what is going on, please?Shermanshermie
Envs is an arbitrary choice. I like venv better as it is all lowercase :) Re fork: Resource temporarily unavailable you might have reached your system’s maximum number of processes (either system-wide or per user or you ran out of memory).Galina
S
2

I am on Mac OS X 10.9.2 and for me virtualenvwrapper.sh file was present in

/usr/local/bin/virtualenvwrapper.sh

So I simply copied this into ~/.profile file:

source /usr/local/bin/virtualenvwrapper.sh

And now my ~/.profile file looks something like this:

# MacPorts Installer addition on 2014-02-23_at_17:28:39: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.

source /usr/local/bin/virtualenvwrapper.sh

And now I am able to use virtualenvwrapper commands without any issue whatsoever

Stonebroke answered 25/4, 2014 at 3:7 Comment(0)
P
1

Users of the Anaconda (from Continuum) distribution of Python should note that

sudo pip install virtualenvwrapper

will be anaconda-aware. So if you

which python

that should give you an idea of where to point your virtualenv in your .bashrc and/or .profile configuration files.

Pandich answered 24/7, 2014 at 13:53 Comment(1)
pip can link to another python. which pip and pip -V will give you a better idea to which python pip is linked to and therefore virtualenvwrapper.Galina

© 2022 - 2024 — McMap. All rights reserved.