Created
February 25, 2020 08:09
-
-
Save andgineer/345eac0abb9149c165b64bf0d9c8694e to your computer and use it in GitHub Desktop.
Python virtual environment create and activate
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
#!/usr/bin/env bash | |
# | |
# "Set-ups or/and activates development environment" | |
# | |
VENV_FOLDER="venv" | |
PYTHON="python3.7" | |
RED='\033[1;31m' | |
GREEN='\033[1;32m' | |
CYAN='\033[1;36m' | |
NC='\033[0m' # No Color | |
if ! (return 0 2>/dev/null) ; then | |
# If return is used in the top-level scope of a non-sourced script, | |
# an error message is emitted, and the exit code is set to 1 | |
echo | |
echo -e $RED"This script should be sourced like"$NC | |
echo " . ./activate.sh" | |
echo | |
exit 1 | |
fi | |
# virtual env | |
if [[ ! -d ${VENV_FOLDER} ]] ; then | |
echo -e $CYAN"Creating virtual environment for python in ${VENV_FOLDER}"$NC | |
$PYTHON -m venv ${VENV_FOLDER} | |
. ${VENV_FOLDER}/bin/activate | |
pip install -r requirements.txt | |
else | |
echo -e $CYAN"Activating virtual environment ..."$NC | |
. ${VENV_FOLDER}/bin/activate | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment