Created
October 27, 2015 04:56
-
-
Save gcv/2f60ee32202fc1d32462 to your computer and use it in GitHub Desktop.
Python isolated virtualenv scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pve() { | |
local pd=~/.python | |
local env_name=$1 | |
if [[ -z ${env_name} ]]; then | |
if [[ -z ${VIRTUAL_ENV} ]]; then | |
echo "usage: pve{2,3} <envname>" | |
return 1 | |
else | |
deactivate | |
return 0 | |
fi | |
fi | |
if [[ ! -e ${pd} ]]; then | |
echo "${pd} not found" | |
return 1 | |
fi | |
local system_python=$2 | |
if [[ ! -f "${system_python}" ]]; then | |
echo "no system python found" | |
return 1 | |
fi | |
pushd ${pd} | |
if [[ ! -f virtualenv.py ]]; then | |
curl -L -O https://raw.github.com/pypa/virtualenv/master/virtualenv.py | |
fi | |
if [[ ! -d ${env_name} ]]; then | |
echo "installing virtualenv" | |
${system_python} virtualenv.py ${env_name} --no-setuptools | |
if [[ ! -f get-pip.py ]]; then | |
curl -L -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py | |
fi | |
${env_name}/bin/python ./get-pip.py | |
fi | |
echo "switching to existing Python environment ${env_name}" | |
source "${env_name}/bin/activate" | |
popd | |
} | |
function pve2() { | |
local system_python | |
if [[ -f `which python2` ]]; then | |
system_python=`which python2` | |
elif [[ -f `which python2.7` ]]; then | |
system_python=`which python2.7` | |
elif [[ -f `which python2.6` ]]; then | |
system_python=`which python2.6` | |
else | |
echo "no system python2 found" | |
return 1 | |
fi | |
pve "$1" "${system_python}" | |
} | |
function pve3() { | |
local system_python | |
if [[ -f `which python3` ]]; then | |
system_python=`which python3` | |
elif [[ -f `which python3.5` ]]; then | |
system_python=`which python3.5` | |
else | |
echo "no system python3 found" | |
return 1 | |
fi | |
pve "$1" "${system_python}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copy these functions into your shell startup script:
.zshrc
or.bash_profile
.