Skip to content

Instantly share code, notes, and snippets.

@pankaj28843
Created August 13, 2017 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pankaj28843/4c138edd17f62456aa7de29555475cf9 to your computer and use it in GitHub Desktop.
Save pankaj28843/4c138edd17f62456aa7de29555475cf9 to your computer and use it in GitHub Desktop.
function create_virtualenv(){
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
project_name=$(basename "$(pwd)");
project_dir=$(pwd);
virtualenv_dir="$HOME/.virtualenvs/$project_name";
virtualenv_dir=${1:-$virtualenv_dir};
if [ -d "$virtualenv_dir" ]; then
echo "${YELLOW}virtualenv alreay exists at \"$virtualenv_dir\".${YELLOW}"
return
fi
# ensure parent directory exists
parent_dir=$(dirname "$virtualenv_dir");
if [ ! -d "$parent_dir" ]; then
mkdir -p "$parent_dir";
fi
python3.6 -m venv "$virtualenv_dir";
if [ ! -d "$virtualenv_dir" ]; then
echo "${RED}virtualenv creation failed.${RED}"
return
fi
echo "$project_dir" > "$virtualenv_dir/.project"
echo "${GREEN}virtualenv created successfuly at \"$virtualenv_dir\".${GREEN}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment