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 | |
} |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For development purposes on my local box, I have all the virtual envs in a centralized location
/home/$USER/virtualsevs/
Your current resource config assumes that I have (or will need) a virtual environment in the CWD. Is there a way to ask the user for the path they want to configure their virtual environment at?