Last active
June 30, 2016 06:00
-
-
Save TaurusOlson/35feae2a7552b6f29edece1c09cd9d9e to your computer and use it in GitHub Desktop.
A bash sript creating a temporary Python virtual environment with optional packages.
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
#! /bin/bash | |
function usage() { | |
cat <<EOF | |
Create a temporary Python virtual environment with optional packages. | |
Usage: | |
$(basename $0) [package1 package2...] | |
EOF | |
} | |
if [ $# -eq 1 ]; then | |
[ $1 = '-h' ] || [ $1 = '--help' ] && usage && exit 1 | |
fi | |
venv_name=venv_temp_$(date +'%Y%m%d%H%M') | |
echo -e "\n* Creating the virtual environment $venv_name...\n" | |
virtualenv $venv_name | |
source $venv_name/bin/activate | |
# Install ipython | |
pip install -q ipython | |
packages="$@" | |
for package in $packages; do | |
echo -e "\n* Installing $package..." | |
pip install -q $package | |
[ $? -eq 0 ] && echo "> Succeded" | |
[ $? -eq 1 ] && echo "> Failed" | |
done | |
$venv_name/bin/ipython | |
echo -e "\n* Removing the virtual environment $venv_name.\n" | |
rm -r $venv_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
creates a virtual environment named venv_temp_YYYYMMDDhhmm
where YYYYMMDDhhmm designates the current date and time.
creates a virtual environment named venv_temp_YYYYMMDDhhmm and installs the packages requests and records.
After the installation, ipython is launched. When you're done, CTRL-d or exit will exit ipython and remove the virtual environment.