Created
January 20, 2024 10:34
-
-
Save munabedan/6a5e8c104228943a461095a9e103a5af to your computer and use it in GitHub Desktop.
Making python virtual environments less of an annoyance to use
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
venv() { | |
# Check if already activated | |
if [[ "$VIRTUAL_ENV" != "" ]]; then | |
echo -e "\n\e[1;33mDeactivating current virtual environment...\e[0m" | |
deactivate | |
return | |
fi | |
# Check if the venv directory exists | |
if [ -d "venv" ]; then | |
echo -e "\n\e[1;33mActivating virtual environment...\e[0m" | |
source venv/bin/activate | |
else | |
echo -e "\n\e[1;33mCreating and activating virtual environment...\e[0m" | |
python3 -m venv venv | |
source venv/bin/activate | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I guess I can add that in but currently it just creates a venv in the default DIR which happens to be CWD by running
python3 -m venv venv
You can always change the above to be
python -m venv /path/to/new/virtual/environment