Created
July 8, 2022 17:27
-
-
Save cupdike/6a9caaf18f30250364c8fcf6d64ff22e to your computer and use it in GitHub Desktop.
Python Disposable Virtual Environment Using Venv Package
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 venvtemp { | |
# Inspired by: https://gist.github.com/csinchok/9714005#file-bash_profile | |
THROWAWAY_DIR=$(mktemp -d -t venv); | |
cd $THROWAWAY_DIR; | |
python3 -m venv venv; | |
source venv/bin/activate; | |
printf "\n\nMaybe run:\n\tpython -m pip install --upgrade pip wheel setuptools\n\n" | |
printf "Consider:\n\texport PIP_DEFAULT_TIMEOUT=100 && python -m pip install <PACKAGES> \\\t | |
--trusted-host=pypi.python.org --trusted-host=pypi.org --trusted-host=files.pythonhosted.org\n\n" | |
} |
And actually, I figured why not use this for permanent virtualenvs by having it take an optional directory name (but still create on in a temp dir if param is not provided:
venvmake () {
if [[ "$1" != "" ]]
then
local venv_dir=$1
mkdir "$venv_dir"
else
local venv_dir="$(mktemp -d -t venv)"
fi
cd $venv_dir
python3 -m venv venv
source venv/bin/activate
printf "\n\nMaybe run:\n\tpython -m pip install --upgrade pip wheel setuptools\n\n"
printf "Consider:\n\texport PIP_DEFAULT_TIMEOUT=100 && python -m pip install <PACKAGES> \\\t --trusted-host=pypi.python.org --trusted-host=pypi.org --trusted-host=files.pythonhosted.org\n\n"
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some different design choices from:
https://gist.github.com/csinchok/9714005#file-bash_profile