Skip to content

Instantly share code, notes, and snippets.

@chrischoy
Last active February 5, 2018 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrischoy/91be70ad4799fa76d7638bba20bc4016 to your computer and use it in GitHub Desktop.
Save chrischoy/91be70ad4799fa76d7638bba20bc4016 to your computer and use it in GitHub Desktop.
Python 3 virtual env setup
#!/bin/sh
ENVNAME=$1
# Directory that contains the venvs
PYV_ROOT=${HOME}
ENV_ROOT="${PYV_ROOT}/.pyv/${ENVNAME}/bin"
# Check the number of arguments
if [ "$#" -eq 1 ] && [ -d "${ENV_ROOT}" ]; then
echo "Activating ${1}"
export OLD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
export OLD_PATH=$PATH
export OLD_PS1="$PS1"
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
export PATH=${PYV_ROOT}/.pyv/${ENVNAME}/bin:/usr/local/cuda/bin:$PATH
export PS1="(${ENVNAME})$PS1"
else
echo "Please put the environment name as argument, you put ${1}" >&2
fi
export LD_LIBRARY_PATH=$OLD_LD_LIBRARY_PATH
export PATH=$OLD_PATH
export PS1=$OLD_PS1
#!/bin/sh
set -e
ENVNAME=$1
# Directory that contains the venvs
PYV_ROOT=${HOME}
# Check the number of argument
if [ "$#" -eq 1 ]; then
ENV_ROOT=${PYV_ROOT}/.pyv/${ENVNAME}
PYTHON_ROOT=${PYV_ROOT}/.pyv/python3/
mkdir -p ${ENV_ROOT}
# Python3
wget -q -O- https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz | tar -xz -C "${PYV_ROOT}/.pyv/"
mv "${PYV_ROOT}/.pyv/Python-3.6.4" ${PYTHON_ROOT}
cd ${PYTHON_ROOT}
./configure --prefix=${PYTHON_ROOT}
make -j8
make install
# Virtual environment setup
export OLD_PATH=$PATH
export PATH=${PYTHON_ROOT}/bin:$PATH
python3.6 -m venv ${ENV_ROOT}
cd ${PYV_ROOT}
source activate ${ENVNAME}
# Install custom libraries
pip3.6 install ipython
else
echo "Please put the server name and the environment name, you put ${1}" >&2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment