Running Python with n8n

Just wanted to add on 1 issue i encountered while building the dockerfile,
I got:
ERROR: Unable to lock database: Permission denied
ERROR: Failed to open apk database: Permission denied

to get around it, i modified the dockerfile to
FROM n8nio/n8n
USER root
RUN apk add --update python3 py3-pip

USER root will make sure the container was run as root and allโ€™s well.

1 Like

This is not a good practice.

You should avoid using root.

To solve your issue, use USER in dockerfile:

USER root
Install your package or run your commands

USER n8n # Go back to normal user

Can you please send a new link to the instructions?

Hi Everyone,

Iโ€™ve found N8N to be quite competent at running python through the command node.

Iโ€™ve run python libraries like pyautogui, pytesseract, and opencv

If you want to see the command lines I made a free library:

N8N as an RPA Node Library

Hope it helps!

2 Likes

Did you find a way to do this? Or has it already been implemented since then?
Thanks!

I added this to my Dockerfile:

# Use the official n8n image as the base
FROM docker.n8n.io/n8nio/n8n:latest AS base

# this ๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡
USER root
RUN apk add --no-cache python3 py3-pip && \
    python3 -m pip install --break-system-packages pipx
USER node
# ...

And now I can run whatever python package right from Execute Command node:

pipx run <python package>

E.g.

pipx run httpie https://example.com

No need to manually install packages. The only package needed is pipx.

1 Like

Does this still apply? Because I found this error: > [Errno 138] emscripten does not support processes.

Seems Python runs in restricted env and does not allow thi?

For anyone having difficulties setting up python in n8n, I just made a step-by-step video tutorial showing you how to set up python, pip and pipx inside of your n8n Docker container so you can run python scripts and apps.

You can watch the video here: https://youtu.be/Z-3rY3Rku20

1 Like

Thanks,
Python is the king in all data projects, โ€ฆ

1 Like

It truly is!