Hi @ISK-VAGR,
Welcome to the community!
To run a Python script with n8n using a virtual environment, you can use the Execute Command node. It basically runs shell commands on the host so if you can run the python script from the shell you can also do it from n8n. Just make sure your n8n user has permissions for the venv and activate the venv in the beginning of your shell command.
And
Here are some examples on how to activate python venv on different OS
Linux/macOS:
source /path/to/venv/bin/activate && python /path/to/script.py
Windows (Command Prompt):
\path\to\venv\Scripts\activate.bat && python \path\to\script.py
Windows (PowerShell):
& \path\to\venv\Scripts\Activate.ps1; python \path\to\script.py
Alternative Method:
Directly specify the Python interpreter from your virtual environment:
Bash:
/path/to/venv/bin/python /path/to/script.py
Docker:
If n8n runs in Docker, create a custom image that includes your virtual environment and dependencies OR mount them as a volume.
Here is another thread from the n8n community where a similar challenge has been discussed.
I hope that helps.