How to run python script in virtual environment?

Describe the problem/error/question

I’m trying to run a python script in a virtual environment using the Execute Command node but it gives error. I tried testing the command in putty and it works but it doesn’t work within n8n. I can’t activate the virtual environment.

What is the error message (if any)?

Command failed: source /var/www/comic.adoreanime.com/htdocs/project/bin/activate /bin/sh: 1: source: not found

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 2.0.3
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm
  • Operating system: Ubuntu 24.04 LTS

In n8n’s Execute Command node, the command is executed with /bin/sh by default

source is a bash builtin, and does not exist in /bin/sh

That’s exactly what this error means:

/bin/sh: 1: source: not found

Use the Code node to run python script

I can’t use the Code node cause the python script is complicated so I want to run it externally

instead of using source which is not available for linux’s /bin/sh, you can use POSIX Standard which is a dot ( . ) which should work

change this

source /var/www/comic.adoreanime.com/htdocs/project/bin/activate

to

. /var/www/comic.adoreanime.com/htdocs/project/bin/activate
2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.