ModuleNotFoundError when activating venv in CGI script

Hi everybody,

Iā€™m new to using the transformers library and have been experimenting with it via pytorch and venv.

If I activate the previously installed virtual environment from a shell, it works just fine.
However, not if I activate it in a python CGI script, like so:

import subprocess

# Defining function for activating/deactivating virtual environment
def activate_virtual_environment():

    # Build the path to the activation script
    activation_script = f"/xampp/htdocs/cgi_bin/env/Scripts/activate"

    # Activate the virtual environment using subprocess
    subprocess.run([activation_script], shell=True)

def deactivate_virtual_environment():
    # Deactivate the virtual environment using subprocess
    subprocess.run(["deactivate"], shell=True)

# Activating virtual environment
activate_virtual_environment()

# Importing 'pipeline' 
from transformers import pipeline

If i activate the virtual environment like this, I get a ā€œModuleNotFoundError: No module named ā€˜transformersā€™ā€, when the script is executed.

The path to the virtual environment is definitely correct, what am I overlooking?
Thanks in advance for your guidance :slight_smile: