Skip to content

Python Workers: ModuleNotFoundError: No module named 'workers' on deploy, even with official pywrangler init scaffold #212

Description

@swiercnas-hash

What versions & operating system are you using?

System:
OS: Windows 10 10.0.19045
CPU: Intel Core i5-4300U
Binaries:
Node: 24.18.0
npm: 11.16.0
npmPackages (worker project):
wrangler: 4.123.0
workers-py: 1.16.4
workers-runtime-sdk: 1.6.13

Please provide a link to a minimal reproduction

No hosted repo needed - reproduces with the official scaffold itself: uvx --from workers-py pywrangler init myapp --accept-defaults --no-deploy --no-git --no-open then cd myapp && uv run pywrangler deploy (unmodified generated entry.py/pyproject.toml/wrangler.jsonc).

Describe the Bug

Deploying any Python Worker fails at the Cloudflare API validation step with a ModuleNotFoundError for the 'workers' package - even the entry.py generated by the official scaffold.

Steps to reproduce:

  1. uvx --from workers-py pywrangler init myapp --accept-defaults --no-deploy --no-git --no-open
    1. cd myapp
    1. uv run pywrangler deploy
      Expected: deploy succeeds with the unmodified generated template.
      Actual: fails with the error pasted below. The traceback shows it originates from Cloudflare's own internal introspection.py trying from workers import (...), not from user code - the generated entry.py's own from workers import Response, WorkerEntrypoint line is where it dies.

I also tried a hand-written minimal Worker (single file, async def on_fetch(request, env) + js.Response.new(...), zero dependencies, wrangler.toml with only compatibility_flags = ["python_workers"]) via plain wrangler deploy - identical error.

Things I tried that did not fix it:

  • compatibility_flags: ["python_workers", "disable_python_external_sdk"] - gets past this specific error, but then fails differently with "The uploaded script has no registered event handlers" [code: 10068].
    • Upgrading wrangler 4.112.0 -> 4.123.0 - no change.
      • Empty requirements.txt, and requirements.txt containing just "workers" - no change (this was before I found the pywrangler/pyproject.toml flow; same error persists with that flow too).
        Account is on the Workers Free plan, if relevant.

Please provide any relevant error logs

X [ERROR] A request to the Cloudflare API (/accounts/.../workers/scripts/myapp/versions) failed.

Uncaught Error: PythonError: Traceback (most recent call last):
File "/lib/python313.zip/_pyodide/_base.py", line 523, in eval_code
.run(globals, locals)
~~~^^^^^^^^^^^^^^^^^
File "/lib/python313.zip/_pyodide/_base.py", line 357, in run
coroutine = eval(self.code, globals, locals)
File "", line 9, in
File "/lib/python313.zip/_pyodide/_base.py", line 666, in pyimport_impl
res = import(stem, fromlist=fromlist)
File "/session/metadata/entry.py", line 10, in
from workers import Response, WorkerEntrypoint
File "/lib/python3.13/site-packages/workers/init.py", line 3, in
raise err
ModuleNotFoundError: No module named 'workers'
You need to update to workers-py >= 1.90 or to pass disable_python_external_sdk

at null.<anonymous> (pyodideRuntime-internal:emscriptenSetup:19919:14) in new_error
at [object Object] in $wrap_exception
at [object Object] in $pythonexc2js
at null.<anonymous> (pyodideRuntime-internal:emscriptenSetup:22411:37) in callPyObjectKwargs
at null.<anonymous> (pyodideRuntime-internal:emscriptenSetup:23309:20) in callKwargs
at null.<anonymous> (pyodideRuntime-internal:emscriptenSetup:24469:87) in runPython
at null.<anonymous> (pyodide:python-entrypoint-helper:73:17) in handleSrcImport
at null.<anonymous> (pyodide:python-entrypoint-helper:190:17)

[code: 10021]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions