| Below is a shell script that activates a Python virtual environment and then runs a specific Python script. Assuming: - The virtual environment is located in a directory named
venv. - The Python script you want to run is named
script.py.
Here is the shell script: #!/bin/bash
# Set the virtual environment directory and the Python script
VENV_DIR="venv"
SCRIPT_NAME="script.py"
# Activate the virtual environment
source "$VENV_DIR/bin/activate"
# Run the Python script
python "$SCRIPT_NAME"
# Deactivate the virtual environment
deactivate
Steps to Use the Script:- Save this shell script to a file, e.g.,
run_script.sh. Give the script execute permissions: chmod +x run_script.sh
Run the script: ./run_script.sh
This script activates the virtual environment, runs the specified Python script, and then deactivates the virtual environment. Adjust the VENV_DIR and SCRIPT_NAME variables as needed for your specific setup. |