This Bash script automatically activates a Python virtual environment, runs the main script main.py, and then deactivates the environment. It is convenient for quickly launching a project without the need to manually enter commands. Developers can use it to simplify their work and minimize errors when setting up the runtime environment.

The script first determines the path to the directory where it is located, and then changes to that directory. This ensures that the commands are executed in the correct context. The virtual environment is then activated, allowing the necessary dependencies to be used. After executing main.py, the virtual environment is deactivated to avoid conflicts with system libraries. This approach is especially useful when developing and deploying Python applications.

#!/bin/bash
BASEDIR=`dirname $0`
PROJECT_PATH=`cd $BASEDIR; pwd`

cd $PROJECT_PATH
source .venv/bin/activate
python main.py
deactivate