Skip to content

Commit 0956fc3

Browse files
frenzymadnessjasonamyers
authored andcommitted
Merged in master (pull request #73)
Find the highest Python version with installed virtualenvwrapper Approved-by: Doug Hellmann
2 parents aa2ac7f + 0ea7893 commit 0956fc3

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

virtualenvwrapper.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,28 @@
4545
#
4646

4747
# Locate the global Python where virtualenvwrapper is installed.
48+
# Use the highest Python version
4849
if [ "${VIRTUALENVWRAPPER_PYTHON:-}" = "" ]
4950
then
50-
VIRTUALENVWRAPPER_PYTHON="$(command \which python)"
51+
for NAME in python3 python2 python
52+
do
53+
python_executable="$(which $NAME 2>/dev/null)"
54+
if ! [ -z "$python_executable" ]
55+
then
56+
if $python_executable -m 'virtualenvwrapper.hook_loader' --help >/dev/null 2>&1
57+
then
58+
VIRTUALENVWRAPPER_PYTHON=$python_executable
59+
break
60+
fi
61+
fi
62+
done
63+
if [ "${VIRTUALENVWRAPPER_PYTHON:-}" = "" ]
64+
then
65+
echo -e "ERROR: Python with virtualenvwrapper module not found!
66+
Either, install virtualenvwrapper module for standard python2
67+
or python3 or set VIRTUALENVWRAPPER_PYTHON variable manually." 1>&2
68+
return 1
69+
fi
5170
fi
5271

5372
# Set the name of the virtualenv app to use.

0 commit comments

Comments
 (0)