Last active
February 28, 2021 19:42
-
-
Save ines/c00535e6ac294750ddba95fd24a77db5 to your computer and use it in GitHub Desktop.
Command to activate / create Python virtual environmment
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
function venv { | |
default_envdir=".env" | |
envdir=${1:-$default_envdir} | |
if [ ! -d $envdir ]; then | |
python -m venv $envdir | |
pip install ipython black flake8 | |
echo -e "\x1b[38;5;2m✔ Created virtualenv $envdir\x1b[0m" | |
fi | |
source $envdir/bin/activate | |
export PYTHONPATH=`pwd` | |
echo -e "\x1b[38;5;2m✔ Activated virtualenv $envdir\x1b[0m" | |
python --version | |
} |
I like the function a lot!
I don't think line 7 installs to the virtualenv (activate then pip freeze
to check).
Maybe something like the below would install to the venv:
function venv {
default_envdir=".env"
envdir=${1:-$default_envdir}
if [ ! -d $envdir ]; then
python3.7 -m venv $envdir
echo -e "\x1b[38;5;2m✔ Created virtualenv $envdir\x1b[0m"
source $envdir/bin/activate
echo -e "\x1b[38;5;2m✔ Activated virtualenv $envdir\x1b[0m"
pip install ipython black flake8
echo -e "\x1b[38;5;2m✔ Packages installed"
fi
if [ -d $envdir ]; then
source $envdir/bin/activate
echo -e "\x1b[38;5;2m✔ Activated virtualenv $envdir\x1b[0m"
fi
export PYTHONPATH=`pwd`
python --version
}
Here's a fish port of the same script:
function venv
set envdir $argv[1]
if not test -d $envdir
command python3 -m venv $envdir
command pip3 install numpy pandas seaborn
echo -e "\x1b[38;5;2m✔ Created virtualenv $envdir\x1b[0m"
end
source $envdir/bin/activate.fish
set PYTHONPATH "pwd"
echo -e "\x1b[38;5;2m✔ Activated virtualenv $envdir\x1b[0m"
command python --version
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! Do you need to activate the environment before you install dependencies on line 7?