Created
September 1, 2023 13:51
-
-
Save iomarmochtar/de9cf06dd6244b544d805f843773398d to your computer and use it in GitHub Desktop.
Simple venv per directory based on python version
This file contains hidden or 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
# 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