Question

On arch linux, after install virtualenvwrapper system-wide, via sudo pip2 install virtualenvwrapper and adding this in my user's .bash_profile,

 export WORKON_HOME=/home/myuser/.virtualenvs
 export PROJECT_HOME=/home/myuser/work
 source /usr/bin/virtualenvwrapper.sh

An error shows up whenever I launch a new shell window:-

which: no python in (/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/core_perl)
-bash: : command not found
virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON= and that PATH is set properly.

This can be traced to line 50 in the virtualenvwrapper.sh script:-

 47 # Locate the global Python where virtualenvwrapper is installed. 
 48 if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ] 
 49 then 
 50     VIRTUALENVWRAPPER_PYTHON="$(\which python)" 
 51 fi 

And is a result of the conflict with arch linux's convention of using python2 for python 2.7 installation.

If I modify line 50 to which python2, everything works perfectly and I will not see the error message whenever I launch a new shell.

What is the appropriate way of resolving this problem? Do I write an explicit check that the current OS is arch linux and introduce an if-else condition to use which python2 in virtualenvwrapper.sh and send the patch to the virtualenvwrapper author? Or is there something I can do with my configuration in my arch linux machine?

Était-ce utile?

La solution 2

To answer this arch-specific python quirk (the convention of using python2), I specifically create a soft link like this:-

ln -s /usr/bin/python2 /usr/local/bin/python

Since /usr/local/bin precedes /usr/bin in the bash system PATH environment variable, when I type python, or when the virtualenvwrapper.sh script refers to which python in line 50, we will no longer run into the above mentioned virtualenvwrapper conflict and everything works as expected.

The disadvantage of doing this is that it might mess up the "python 3" (being considered as the default python command) conventions arch linux is designed for. So care has to be taken that I do not use python 3 related libraries or package installations relating to python 3 in my target box.

Autres conseils

Virtualenvwrapper has variables VIRTUALENVWRAPPER_PYTHON and VIRTUALENVWRAPPER_VIRTUALENV which point to your python and virtualenv executables. So, in your .bash_profile you can write something like:

export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python2
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv2
source /usr/bin/virtualenvwrapper.sh

I found there is no need to edit the /usr/bin/virtualenvwrapper.sh script or create a new symbolic link. I was just missing the virtualenvwrapper module for python2. I installed it like the following:

pip2 install virtualenvwrapper

and keeped the exports so the magic is done.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top