🐛 BUG:Python dependency packages cannot be correctly imported on worker
Which Cloudflare product(s) does this pertain to?
Workers Runtime
What version(s) of the tool(s) are you using?
What version of Node are you using?
Python 3.10.12
What operating system and version are you using?
Ubuntu 22.04
Describe the Bug
Observed behavior
Python dependency packages cannot be correctly imported on worker, I want to imported requests package, but the requests depend on the urlib3, when i importing the failed happened. I had download the dependency package to the local.
Uncaught Error: PythonError: Traceback (most recent call last):
File "/lib/python312.zip/_pyodide/_base.py", line 629, in pyimport_impl
res = import(stem, fromlist=fromlist)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/session/metadata/entry.py", line 4, in
at null.<anonymous> (pyodide-internal:generated/pyodide.asm:20:9998) in new_error
at [object Object] in $wrap_exception
at [object Object] in $pythonexc2js
at null.<anonymous> (pyodide-internal:generated/pyodide.asm:20:607956) in Module._pythonexc2js
at null.<anonymous> (pyodide-internal:generated/pyodide.asm:20:64098) in
Module.callPyObjectKwargs
at null.
Expected behavior
npx wrangler deploy
Steps to reproduce
The simple worker file
from js import Response
import requests async def on_fetch(request, env): return Response.new("Hello world!")
Please provide a link to a minimal reproduction
No response
Please provide any relevant error logs
Uncaught Error: PythonError: Traceback (most recent call last):
File "/lib/python312.zip/_pyodide/_base.py", line 629, in pyimport_impl
res = import(stem, fromlist=fromlist)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/session/metadata/entry.py", line 4, in
at null.<anonymous> (pyodide-internal:generated/pyodide.asm:20:9998) in new_error
at [object Object] in $wrap_exception
at [object Object] in $pythonexc2js
at null.<anonymous> (pyodide-internal:generated/pyodide.asm:20:607956) in Module._pythonexc2js
at null.<anonymous> (pyodide-internal:generated/pyodide.asm:20:64098) in
Module.callPyObjectKwargs
at null.
I'll ping the team working on Python support in Workers to take a look at this.
Can you share your worker's full directory structure (including the file's contents)? Your Python script looks good, but are you also creating a requirements.txt file with requests in there?
Can you share your worker's full directory structure (including the file's contents)? Your Python script looks good, but are you also creating a requirements.txt file with
requestsin there?
The tutorial informs me that, for the time being, it does not support installing all dependencies through requirements.txt, so I have packaged all the dependencies locally. It is almost an empty project. The requirements.txt is also empty.
I'm also having this issue, I'm using pywrangler
# pyproject.toml
[project]
name = "ai"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = ["langchain_core", "langchain_openai"]
[dependency-groups]
dev = ["workers-py"]