0

I have written a short script to speed up creating, entering, and installing requirements into a virtual environment. The code is below:

#!/bin/bash
red=$(printf '\033[31m')
reset=$(printf '\033[0m')
rm -rf .venv
python3 -m venv .venv
source .venv/bin/activate
echo '*' > .venv/.gitignore
if [ -f "requirements.txt" ]
then
        pip install -r requirements.txt
fi
echo $red"Virtual Environment Created"$reset

The part giving me problems is the source .venv/bin/activate line, as it doesn't actually run the activate file in the venv - all the requirements get installed to my local machine directly.

How can I make it switch to the venv?

vs07
  • 195
  • 8

1 Answers1

0

I've fixed it. Instead of calling venv to run the script (as I placed it in /bin), I could just run . venv to run it properly. It was answered here.

Additionally, by setting an alias venv='. venv, I could simply call venv and have it work.

vs07
  • 195
  • 8