Hi,
I am new in n8n and I want to run an python script as i will be in VSC to automate it.
However, I don’t know how to add the virtual environment to n8n so that it uses the packages and the imports., etc. Is that even possible?
Thanks in Advance
AG
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.
2 Likes
is there a chance to tunnel the python script node with socks5 proxy?
Hi @Exodus_IGX
If your Python script requires SOCKS5 proxy access, you’ll need to configure that directly within the Python script itself, using libraries like PySocks
.
The n8n Command code just executes the script as a separate process so the networking is handled at the host/script level.
1 Like