Reputation: 2400
I'm new to Python virtual environments, so after reading this tutorial I tried to create my first environment using virtualenvwrapper
. My python3 installation is at the bare bones now:
$ pip3 list
argparse (1.2.1)
pip (1.5.6)
setuptools (2.1)
stevedore (0.15)
virtualenv (1.11.6)
virtualenv-clone (0.2.5)
virtualenvwrapper (4.3.1)
As suggested by the tutorial, I added the following lines to my .bashrc file:
export WORKON_HOME=$HOME/.virtualenvs
source /Library/Frameworks/Python.framework/Versions/3.4/bin/virtualenvwrapper_lazy.sh
which results in the following message when I open a new Terminal:
Last login: Wed Sep 10 22:33:17 on ttys006
-bash: _VIRTUALENVWRAPPER_API: unbound variable
-bash: VIRTUALENVWRAPPER_SCRIPT: unbound variable
-bash: VIRTUALENVWRAPPER_SCRIPT: unbound variable
-bash: _VIRTUALENVWRAPPER_API: unbound variable
-bash: _VIRTUALENVWRAPPER_API: unbound variable
complete: usage: complete [-abcdefgjksuv] [-pr] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [name ...]
I don't understand what the problem is, but clearly the source /Library/Frameworks/Python.framework/Versions/3.4/bin/virtualenvwrapper_lazy.sh
line fails because then I can't even find the mkvirtualenv
command:
$ mkvirtualenv test1 -p /usr/bin/python3.3
-bash: mkvirtualenv: command not found
I found this post and this one, with similar problems, but none of them gave me a solution.
Upvotes: 17
Views: 55792
Reputation: 51
I ran into the same problem and I fixed it with by following the tutorial:
http://exponential.io/blog/2015/02/10/install-virtualenv-and-virtualenvwrapper-on-ubuntu/
sudo apt-get install python-pip python-dev build-essential
sudo pip install virtualenv virtualenvwrapper
sudo pip install --upgrade pip
I used vim to edit ~/.bashrc.
Firstly, install vim with the command:
sudo apt-get install vim
Secondly, edit ~/.bashrc
vi .bashrc
enter [Shift] + [g] //G (shift + g): to go the end of the file
enter [a] //Type a to edit the file
Then insert three lines:
export WORKON_HOME=~/virtualenvs
export VIRTUALENVWRAPPER_PYTHON=[link-to-python-folder]
source /usr/local/bin/virtualenvwrapper.sh
where [link-to-python-folder]
can be, for example:
export VIRTUALENVWRAPPER_PYTHON=/user/bin/python3
export VIRTUALENVWRAPPER_PYTHON=/user/bin/python
Next,
enter [Esc] then :wq
The Esc key means return the command line, :wq means save the changes and exit vi.
source ~/.bashrc
mkdir -p $WORKON_HOME
Now, you can try again with mkvirtualenv:
mkvirtualenv your_project
To enable the 'your_project' virtual environment:
workon your_project
To exit it:
deactivate
I noticed that when I installed separately virtualenv and virtualenvwrapper (with two times of 'sudo pip install'), I failed when run source ~/.bashrc
because of a failure of the importing the module virtualenvwrapper.hook_loader, so although you really installed virtualenv and virtualenvwrapper, let try it one more time with sudo pip install virtualenv virtualenvwrapper
.
Hope you find it useful!
Upvotes: 5
Reputation: 439
export WORKON_HOME=~/Virtualenvs
export PROJECT_HOME=~/Devel
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
source /usr/local/bin/virtualenvwrapper.sh
If you have a clean installation of virtualenv and virtualenvwrapper, then this should work in mac OS. It did for me.
Upvotes: 0
Reputation: 676
I added the following in my .bashrc, referring this
export PATH=/usr/local/bin:$PATH
source /usr/local/bin/virtualenvwrapper.sh
Now mkvirtualenv works-
pkoli@pkoli-SVE15136CNB:~/Desktop$ mkvirtualenv BUGS
Using base prefix '/usr'
New python executable in BUGS/bin/python3
Also creating executable in BUGS/bin/python
Installing setuptools, pip...done.
Upvotes: 33