Skip to content

Instantly share code, notes, and snippets.

@iomarmochtar
Created September 1, 2023 13:51
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 iomarmochtar/de9cf06dd6244b544d805f843773398d to your computer and use it in GitHub Desktop.
Save iomarmochtar/de9cf06dd6244b544d805f843773398d to your computer and use it in GitHub Desktop.
Simple venv per directory based on python version
# put this into your .bashrc or .zshrc, to use it just type pyenvme on target working directory
function pyenvme(){
targetDir=~/pyenvme
test -d $targetDir || mkdir -p $targetDir
curDir=$(pwd)
pyEnvDir=$(echo $curDir | sed -e 's/\//_/g')
# only include for major and minor version
pyVersion=$(python --version | awk '{ print $2 }' | sed -E 's/\.[0-9]+$//')
pyEnvDirPath="${targetDir}/${pyEnvDir}/${pyVersion}"
echo "using ${pyEnvDirPath}"
test -d $pyEnvDirPath || python -m venv $pyEnvDirPath
source $pyEnvDirPath/bin/activate
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment