I am working to set up a Django project on Amazon EC2 with an Ubuntu 14.04 LTS instance. I want to write my code using Python 3. I've been advised that the best way to do this is to use virtualenvwrapper
. I've installed virtualenvwrapper
successfully and put
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.4
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
into my .bashrc
file. Now I see:
/usr/bin/python3.4: Error while finding spec for 'virtualenvwrapper.hook_loader' (<class 'ImportErro
r'>: No module named 'virtualenvwrapper')
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.4 and that PATH is
set properly.
How can I fix this?
Instead of specifying a different python interpreter with -p
flag, you can also config your desired interpreter as default.
According to virtualenvwrapper
's documentation, virtualenvwrapper.sh
finds the first python
and virtualenv
programs on the $PATH
and remembers them to use later.
If your virtualenvwrapper
is not installed on your OS's default python interpreter (/usr/bin/python
), make sure you override the environment variables as below:
VIRTUALENVWRAPPER_PYTHON
to the full path of your python interpreterVIRTUALENVWRAPPER_VIRTUALENV
to the full path of the virtualenvFor example, on my .bash_profile
(Mac):
#virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/Library/Frameworks/Python.framework/Versions/3.5/bin/virtualenv
source /Library/Frameworks/Python.framework/Versions/3.5/bin/virtualenvwrapper.sh
Reload your new variables by running source ~/.bash_profile