NPM N8N v2 Python Code node fails (virtual env missing)

Describe the problem/error/question

I installed n8n self-hosted via npm on Windows and upgraded to n8n v2 (2.0.2).
When using the Code node with Python, n8n always reports that the Python virtual environment is missing, even though Python and the venv are correctly installed and working locally.

I would like to know whether this is a known limitation/bug of n8n v2 when installed via npm on Windows, and if there is any supported way to fix it without Docker.


What is the error message (if any)?

Python runner unavailable: Virtual environment is missing from this system

Internal mode is intended only for debugging. For production, deploy in external mode:
https://docs.n8n.io/hosting/configuration/task-runners/#setting-up-external-mode

At n8n startup:

Failed to start Python task runner in internal mode because its virtual environment is missing from this system.

Please share your workflow

Single Code node
- Language: Python
- Example code: print("hello")

Share the output returned by the last node

No output.
The execution fails before the node runs.


Additional details / troubleshooting done

  • Python and virtual environment work correctly:

    C:\n8n-python310\venv\Scripts\python.exe --version
    Python 3.10.10
    
  • Environment variable set:

    setx N8N_PYTHON_VENV C:\n8n-python310\venv
    
  • Variable is visible in terminal:

    echo %N8N_PYTHON_VENV%
    C:\n8n-python310\venv
    
  • Restarted terminal and system multiple times

  • Tried both python.exe and python3.exe

  • Attempted to start Python runner explicitly:

    n8n python-runner
    

    Result:

    Error: Command "python-runner" not found
    

This suggests that n8n 2.0.2 installed via npm does not expose the Python task runner CLI, even though the documentation references it.


Question

Is it currently not supported to use the Python Code node reliably on Windows + npm install in n8n 2.0.x?

If so:

  • Which minimum n8n version properly supports Python task runners?
  • Is Docker required, or does upgrading n8n fix this issue?

Thanks in advance.


Information on your n8n setup

  • n8n version: 2.0.2
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm
  • Operating system: window
1 Like

Subject: Solution for Python Code Node on Windows with npm install

Hi @T_T_T,

I understand your frustration with this issue. You’ve actually identified a known limitation with n8n 2.0.x when installed via npm on Windows.

The Problem

The Python task runner in n8n v2 has limited support for npm installations on Windows, especially in “internal mode”. The architecture was primarily designed and tested for Docker/Linux environments.

Possible Solutions

Option 1: Use External Mode (Recommended)

Instead of relying on internal mode, set up the Python runner in external mode:

Install the task runner package separately:

npm install -g @n8n/task-runner

Start the task runner in a separate terminal:

set N8N_RUNNERS_TASK_BROKER_URI=localhost:5679

task-runner

Configure n8n to use external mode:

set N8N_RUNNERS_MODE=external

set N8N_RUNNERS_TASK_BROKER_URI=localhost:5679

n8n start

Option 2: Use Docker (Most Reliable)

If possible, switch to Docker which has better support for Python runners:

docker run -it --rm --name n8n -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n

Option 3: Workaround with HTTP Request

For simple Python scripts, you could:

Set up a local Python Flask API

Call it from n8n using HTTP Request node

Not ideal, but works reliably

Option 4: Use JavaScript Instead

If your Python code is simple, consider rewriting it in JavaScript within the Code node, which works seamlessly on Windows.

Direct Answer to Your Questions

Is it currently not supported to use the Python Code node reliably on Windows + npm install?

Partially correct. Internal mode has issues, but external mode should work with proper setup.

Which minimum n8n version properly supports Python task runners?

Python task runners were introduced in n8n 1.50+, but full stability came with 2.0+ - primarily for Docker environments.

Is Docker required?

Not strictly required, but highly recommended for Python workflows. The npm installation on Windows has known quirks with Python integration.

Additional Tips:

Make sure your Python path doesn’t contain spaces

Try using forward slashes in the path: C:/n8n-python310/venv

Check if antivirus is blocking the virtual environment access

Let me know if any of these solutions work for you, or if you need further clarification!

1 Like

I have followed your option 1 (run in cmd not powershell with admin right), however I faced an issue “task-runner is note recognized as an internal or external command”. Specifically:

C:\Users\PC>npm install -g @n8n/task-runner

changed 416 packages in 24s

68 packages are looking for funding
  run `npm fund` for details

C:\Users\PC>set N8N_RUNNERS_TASK_BROKER_URI=localhost:5679

C:\Users\PC>task-runner
'task-runner' is not recognized as an internal or external command,
operable program or batch file.

I saw the task-runner file was created, but it has 0KB in size, no content at all. And in the n8n start terminal, it required the auth token when start, what is this token, how can I get it ?

C:\Users\PC>set N8N_RUNNERS_MODE=external

C:\Users\PC>set N8N_RUNNERS_TASK_BROKER_URI=localhost:5679

C:\Users\PC>set N8N_RUNNERS_TASK_BROKER_URI=localhost:5679

C:\Users\PC>n8n start
Initializing n8n process
n8n ready on ::, port 5678
Error: Missing auth token. When `N8N_RUNNERS_MODE` is `external`, it is required to set `N8N_RUNNERS_AUTH_TOKEN`. Its value should be a shared secret between the main instance and the launcher.
    at TaskRunnerModule.start (C:\Users\PC\AppData\Roaming\npm\node_modules\n8n\src\task-runners\task-runner-module.ts:57:48)
    at Start.init (C:\Users\PC\AppData\Roaming\npm\node_modules\n8n\src\commands\base-command.ts:160:42)
    at Start.init (C:\Users\PC\AppData\Roaming\npm\node_modules\n8n\src\commands\start.ts:202:3)
    at CommandRegistry.execute (C:\Users\PC\AppData\Roaming\npm\node_modules\n8n\src\command-registry.ts:82:4)
    at C:\Users\PC\AppData\Roaming\npm\node_modules\n8n\bin\n8n:63:2
Exiting due to an error.
Missing auth token. When `N8N_RUNNERS_MODE` is `external`, it is required to set `N8N_RUNNERS_AUTH_TOKEN`. Its value should be a shared secret between the main instance and the launcher.

Thank you a lot!

1 Like

running into this same thing tonight in a local/demo environment. spun up the environment, walked through the install. the other thing I seem to have run into is I can’t get the activation code (no errors are displayed?)…

@T_T_T to get a auth token, you just need to generate a random string. here’s an example:

baldpope@n8n-demo:~$ openssl rand -base64 24
Rez6aNDc2CZzRIXPLckxGx7PuBgqYf/Y
baldpope@n8n-demo:~$ N8N_RUNNERS_AUTH_TOKEN=Rez6aNDc2CZzRIXPLckxGx7PuBgqYf/Y N8N_RUNNERS_MODE=external N8N_RUNNERS_TASK_BROKER_URI=localhost:5679 NODES_EXCLUDE="[]" n8n start
Initializing n8n process
n8n ready on ::, port 5678
n8n Task Broker ready on 127.0.0.1, port 5679
[license SDK] Skipping renewal on init: license cert is not initialized
Version: 2.0.2

Editor is now accessible via:
http://localhost:5678

Press "o" to open in Browser.
(node:1162) [DEP0060] DeprecationWarning: The `util._extend` API is deprecated. Please use Object.assign() instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

Hope that helps you with the token piece.

1 Like

Hi @T_T_T,

Great progress! You’re very close to getting it working. Let me help you solve these two issues:

Issue 1: task-runner Command Not Found

The problem is that the task-runner executable wasn’t installed correctly. The 0KB file confirms this. Let’s fix it:

Solution:

Step 1: Find the correct executable path

# In CMD, run:

where node

# This shows your Node.js installation path

# Then check:

dir C:\Users\PC\AppData\Roaming\npm

Step 2: Run task-runner with full path

Instead of just task-runner, use:

npx @n8n/task-runner

Or try:

node C:\Users\PC\AppData\Roaming\npm\node_modules\@n8n\task-runner\dist\start.js

Step 3: Alternative - Use n8n’s built-in runner

n8n task-runner

If this command exists, it’s easier than installing separately.

Issue 2: Missing Auth Token

When using external mode, you need to set an authentication token that both n8n and the task-runner share.

Solution:

Step 1: Generate a random token

You can use any random string as the auth token. For example:

# Generate a simple token (or use any random string)

set N8N_RUNNERS_AUTH_TOKEN=mySecretToken123456

Step 2: Set the token for BOTH n8n and task-runner

Terminal 1 (for task-runner):

set N8N_RUNNERS_AUTH_TOKEN=mySecretToken123456

set N8N_RUNNERS_TASK_BROKER_URI=localhost:5679

npx @n8n/task-runner

Terminal 2 (for n8n):

set N8N_RUNNERS_MODE=external

set N8N_RUNNERS_TASK_BROKER_URI=localhost:5679

set N8N_RUNNERS_AUTH_TOKEN=mySecretToken123456

n8n start

:warning: Important: The token must be identical in both terminals.

Complete Step-by-Step Setup

Let me give you the complete, correct sequence:

Terminal 1 - Start Task Runner First:

# 1. Set auth token (use any random string)

set N8N_RUNNERS_AUTH_TOKEN=MySecureToken2024

# 2. Set broker URI

set N8N_RUNNERS_TASK_BROKER_URI=localhost:5679

# 3. Start task runner

npx @n8n/task-runner

# You should see: “Task runner started and listening…”

Terminal 2 - Start n8n:

# 1. Set the SAME auth token

set N8N_RUNNERS_AUTH_TOKEN=MySecureToken2024

# 2. Set external mode

set N8N_RUNNERS_MODE=external

# 3. Set broker URI

set N8N_RUNNERS_TASK_BROKER_URI=localhost:5679

# 4. Set Python venv path (from your original setup)

set N8N_PYTHON_VENV=C:\n8n-python310\venv

# 5. Start n8n

n8n start

If task-runner Still Doesn’t Work

If the task-runner installation is corrupted, try a fresh reinstall:

# 1. Uninstall

npm uninstall -g @n8n/task-runner

# 2. Clear cache

npm cache clean --force

# 3. Reinstall

npm install -g @n8n/task-runner

# 4. Verify installation

npm list -g @n8n/task-runner

Alternative: Simpler Internal Mode Workaround

If external mode is too complex, you can try forcing internal mode with a manual venv setup:

# 1. Make sure Python venv is activated

C:\n8n-python310\venv\Scripts\activate

# 2. Install required packages

pip install -r C:\Users\PC\AppData\Roaming\npm\node_modules\n8n\packages\task-runner\requirements.txt

# 3. Set venv path

set N8N_PYTHON_VENV=C:\n8n-python310\venv

# 4. Start n8n normally

n8n start

Debugging Tips

Check if task-runner is actually installed:

npm list -g @n8n/task-runner

Check what’s in the installation directory:

dir C:\Users\PC\AppData\Roaming\npm\node_modules\@n8n\task-runner

If the directory is empty or corrupted, the reinstall steps above should fix it.

Quick Summary:

Use npx @n8n/task-runner instead of just task-runner

Set N8N_RUNNERS_AUTH_TOKEN to the same value in both terminals

Start task-runner FIRST, then start n8n

Let me know how it goes! If you’re still stuck, share the output of:

npm list -g @n8n/task-runner

node -v

npm -v

And I can provide more specific help.

I encountered the same problem. You just need to create a docker-compose.yml file according to the documentation: Task runners | n8n Docs , and then start n8n to solve this problem. My configuration is as follows:

1 Like