After following the instructions on Doug Hellman's virtualenvwrapper
post, I still could not fire up a test environment.
[mpenning@tsunami ~]$ mkvirtualenv test
-bash: mkvirtualenv: command not found
[mpenning@tsunami ~]$
It should be noted that I'm using WORKON_HOME
that is not in my $HOME
. I tried looking for /usr/local/bin/virtualenvwrapper.sh
as shown in the virtualenvwrapper
installation docs, but it does not exist.
I'm running CentOS 6 and python 2.6.6, if this matters.
# File: ~/.bash_profile
# ...
export WORKON_HOME="/opt/virtual_env/"
source "/opt/virtual_env/bin/virtualenvwrapper_bashrc"
Solution 1:
For some reason, virtualenvwrapper.sh
installed in /usr/bin/virtualenvwrapper.sh
, instead of under /usr/local/bin
.
The following in my .bash_profile
works...
source "/usr/bin/virtualenvwrapper.sh"
export WORKON_HOME="/opt/virtual_env/"
My install seems to work fine without sourcing virtualenvwrapper_bashrc
Solution 2:
Alternatively as mentioned below, you could leverage the chance that virtualenvwrapper.sh
is already in your shell's PATH
and just issue a source `which virtualenvwrapper.sh`
Try:
source `which virtualenvwrapper.sh`
I had the same issue on OS X 10.9.1 with python 2.7.5. No issues with WORKON_HOME
for me, but I did have to manually add source "/usr/local/bin/virtualenvwrapper.sh"
to ~/.bash_profile
(or ~/.bashrc
in unix) after I ran pip install virtualenvwrapper
Prerequisites to execute this command -
1) pip (recursive acronym of Pip Install Python) is a package management system used to install and manage software packages written in Python. Many packages can be found in the Python Package Index (PyPI).
sudo apt-get install python-pip
2) Install Virtual Environment. Used to create virtual environment, to install packages and dependencies of multiple projects isolated from each other.
sudo pip install virtualenv
3) Install virtual environment wrapper About virtual env wrapper
sudo pip install virtualenvwrapper
After Installing prerequisites you need to bring virtual environment wrapper into action to create virtual environment. Following are the steps -
1) set virtual environment directory in path variable-
export WORKON_HOME=(directory you need to save envs)
2) source /usr/local/bin/virtualenvwrapper.sh -p $WORKON_HOME
As mentioned by @Mike, source `which virtualenvwrapper.sh` or which virtualenvwrapper.sh
can used to locate virtualenvwrapper.sh file.
It's best to put above two lines in ~/.bashrc to avoid executing the above commands every time you open new shell. That's all you need to create environment using mkvirtualenv
Points to keep in mind -
- Under Ubuntu, you may need install virtualenv and virtualenvwrapper as root. Simply prefix the command above with sudo.
- Depending on the process used to install virtualenv, the path to virtualenvwrapper.sh may vary. Find the appropriate path by running $ find /usr -name virtualenvwrapper.sh. Adjust the line in your .bash_profile or .bashrc script accordingly.
On Windows 7 and Git Bash this helps me:
- Create a ~/.bashrc file (under your user home folder)
- Add line export WORKON_HOME=$HOME/.virtualenvs (you must create this folder if it doesn't exist)
- Add line source "C:\Program Files
(x86)\Python36-32\Scripts\virtualenvwrapper.sh" (change path for
your virtualenvwrapper.sh)
Restart your git bash and mkvirtualenv command now will work nicely.
Using Git Bash on Windows 10 and Python36 for Windows I found the virtualenvwrapper.sh in a slightly different place and running this resolved the issue
source virtualenvwrapper.sh
/c/users/[myUserName]/AppData/Local/Programs/Python36/Scripts
Solved my issue in Ubuntu 14.04 OS with python 2.7.6, by adding below two lines into ~/.bash_profile (or ~/.bashrc in unix) files.
source "/usr/local/bin/virtualenvwrapper.sh"
export WORKON_HOME="/opt/virtual_env/"
And then executing both these lines onto the terminal.