Created
March 11, 2024 10:01
-
-
Save yashasolutions/4f2e499822b275bc4d74dbb0dc52f68f to your computer and use it in GitHub Desktop.
venv - create & load virtual environment
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
# add to your .bashrc | |
# for quick project setup | |
function venv () { | |
# if project name is given | |
# create a new venv with the project name | |
# else create default venv | |
if [ -n "$1" ]; then | |
python3 -m venv .venv/$1 | |
elif [ ! -d .venv ]; then | |
python3 -m venv .venv | |
fi | |
# activate the venv | |
# if .venv has more than one subdirectory, load regular venv | |
# else load the project venv | |
if [ $(ls -l .venv/ | grep -c ^d) -gt 1 ]; then | |
source .venv/bin/activate | |
else | |
source .venv/$(ls .venv/)/bin/activate | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment