Error in Python runner: name '_imp' is not defined

Describe the problem/error/question

Hi guys, I’m trying to run some custom Python code using the task runners, but if I do a simple import eg.

import pandas

I see the error:
name '_imp' is not defined

I’ve added pandas to the list of dependencies in extras.txtand I’ve whitelisted it in the n8n-task-runners.json file. I’m pretty sure pandas has been installed into the environment so that shouldn’t be the issue. I’ve tried to import other packages too with the same result.

What is the error message (if any)?

name '_imp' is not defined

Please share your workflow

{“nodes”: [{“parameters”: {},“type”: “n8n-nodes-base.manualTrigger”,“typeVersion”: 1,“position”: [0,0],“id”: “b8a536f0-ec91-4877-a06c-735e418016e4”,“name”: “When clicking ‘Execute workflow’”},{“parameters”: {“language”: “pythonNative”,“pythonCode”: “# Loop over input items and add a new field called ‘my_new_field’ to the JSON of each one\n\nimport pandas as pd\n\nfor item in _items:\n  item["json"]["my_new_field"] = 1\n\nprint("hello world")\nreturn _items”},“type”: “n8n-nodes-base.code”,“typeVersion”: 2,“position”: [208,0],“id”: “0606de20-506c-4bdf-b1fa-94e7204ab140”,“name”: “Code in Python (Native) (Beta)”,“executeOnce”: false}],“connections”: {“When clicking ‘Execute workflow’”: {“main”: [[{“node”: “Code in Python (Native) (Beta)”,“type”: “main”,“index”: 0}]]}},“pinData”: {},“meta”: {“instanceId”: “a106694d47d93eaf1bc0c35004e50b45890d9b6f366af94a5a5d4f39a8eee953”}}

Share the output returned by the last node

Problem in node ‘Code in Python (Native) (Beta)‘
name ‘_imp’ is not defined

Information on your n8n setup

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

I meet the same problem hope n8n team will have video for implementation for External Runners / Python Native soon

I managed to workaround the issue by using the wildcard to allow everything in n8n-task-runners.json, eg.
"N8N_RUNNERS_STDLIB_ALLOW": "*"
"N8N_RUNNERS_EXTERNAL_ALLOW": "*"

I wonder if there’s a bug that occurs when a Python package tries to load one of it’s own dependencies.

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