Import python library with n8nio/n8n:PR-4295-python-code-node : Not found


I have created from n8nio/n8n:PR-4295-python-code-node a new image for using Python Node and some customs library…

FROM n8nio/n8n:PR-4295-python-code-node

COPY requirements.txt requirements.txt

USER root
RUN apk add --update  py-pip  automake gcc g++ subversion python3-dev
RUN pip3 install -r requirements.txt

requirements.txt : Contains “pdfkit”

I build the image, named n8n-python :
docker build -t n8n-python -f DockerFile .

After that, I run it, and open a terminal :
python -c "import pdfkit" => OK

At the end, I try to create a Python Node with the “pdfkit”…

import pyodide_js
await pyodide_js.loadPackage('pdfkit')

ERROR: JsException: Error: No known package with name ‘pdfkit’

import pdfkit

ERROR: ModuleNotFoundError: No module named ‘pdfkit’

I have also used the field defining the imported libraries :

ERROR: Traceback (most recent call last): File "/lib/python3.10/asyncio/", line 201, in result raise self._exception File "/lib/python3.10/asyncio/", line 234, in __step result = coro.throw(exc) File "/lib/python3.10/site-packages/micropip/", line 573, in install await transaction.gather_requirements(requirements) File "/lib/python3.10/site-packages/micropip/", line 333, in gather_requirements await gather(*requirement_promises) File "/lib/python3.10/asyncio/", line 284, in __await__ yield self # This tells Task to wait for completion. File "/lib/python3.10/asyncio/", line 304, in __wakeup future.result() File "/lib/python3.10/asyncio/", line 201, in result raise self._exception File "/lib/python3.10/asyncio/", line 232, in __step result = coro.send(None) File "/lib/python3.10/site-packages/micropip/", line 340, in add_requirement return await self.add_requirement_inner(Requirement(req)) File "/lib/python3.10/site-packages/micropip/", line 432, in add_requirement_inner metadata = await _get_pypi_json(, self.fetch_kwargs) File "/lib/python3.10/site-packages/micropip/", line 48, in _get_pypi_json metadata = await fetch_string(url, fetch_kwargs) File "/lib/python3.10/site-packages/micropip/", line 35, in fetch_string return await (await pyfetch(url, **kwargs)).string() File "/lib/python3.10/pyodide/", line 251, in pyfetch url, await _jsfetch(url, to_js(kwargs, dict_converter=Object.fromEntries)) NameError: name '_jsfetch' is not defined

what did I forget ?
Thanks :wink:

Hi @home, that pull request isn’t finalized yet I am afraid. Meaning I am not sure about the current status, and I am also not familiar with this Python package specifically.

Seeing you are using a custom image anyway you could simply consider installing a standard python binary and then run your Python scripts via the Execute Command node here.

@home Could the problem be that the module gets installed for user root, but n8n is actually running as user node?


import pyodide_js
await pyodide_js.loadPackage('pdfkit')

That is nothing you actually have to run yourself. n8n will run that automatically when you write pdfkit in the “Python Modules” parameter.

And there is also a new Docker image which you should start to use moving forward. It is the v1 release cancidate one:

1 Like