Created
July 16, 2023 00:53
-
-
Save darklinden/41b03f8014815ba8e787d7d32c507d69 to your computer and use it in GitHub Desktop.
shell for enable venv and add pwd to PYTHONPATH
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
#!/bin/bash | |
GLOBAL_PYTHON=$(which python3.10) | |
if [ -z "$GLOBAL_PYTHON" ]; then | |
GLOBAL_PYTHON=$(which python3) | |
fi | |
echo "Using global python: $GLOBAL_PYTHON" | |
CWD=$(pwd) | |
DIR=$CWD"/.env" | |
ACTIVATE=$DIR"/bin/activate" | |
if [ ! -d $DIR ]; then | |
# Take action if $DIR exists. # | |
mkdir $DIR | |
$GLOBAL_PYTHON -m venv $DIR | |
else | |
echo "Virtual environment folder already exists" | |
fi | |
if grep -Faq "$DIR" $ACTIVATE; then | |
# code if found | |
echo "Virtual environment is ready to use" | |
else | |
# code if not found | |
echo "Virtual environment is incorrect, recreating..." | |
rm -rf $DIR | |
# Take action if $DIR exists. # | |
mkdir $DIR | |
$GLOBAL_PYTHON -m venv $DIR | |
fi | |
echo '\n# Virtual Environment' >>$DIR/bin/activate | |
echo 'export PYTHONPATH=$PYTHONPATH:$PWD' >>$DIR/bin/activate | |
source $DIR/bin/activate | |
pip install --upgrade pip | |
pip install -r requirements.txt | |
echo | |
echo "To activate the virtual environment, Please run the following command:" | |
echo " source $DIR/bin/activate" | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment