Skip to content

Run Python with dependencies #189

Closed
Closed
@denniskawurek

Description

@denniskawurek

Describe the bug

Hi,

I wanted to run a Python module with dependencies.

When running the following code, I get an
ModuleNotFoundError: No module named 'bs4'

import bs4

def worker(req):
    res = Response(req.body)
    res.headers["x-generated-by"] = "wasm-workers-server"
    return res

I guess I need to mount my dependencies or install them in wws (?)
But I could not find any documentation about it.

Reproduction steps

  1. Store the above code as index.py
  2. Run it with wws -i
  3. Send a request to the server: http://127.0.0.1:8080

Expected behavior

No error when importing modules.

Additional context

Things I tried:

I checked the documentation, but could not find anything about adding dependencies in python based modules (only Rust).

However I tried to create a _lib directory with the bs4 dependency and mount it.

index.toml

[[folders]]
from = "./_lib"
to = "/mnt/lib"

I adjusted the import to import lib.bs4, but this didn't worked. It says that the lib module is not found.

Thanks,
Dennis

Metadata

Metadata

Assignees

Labels

📝 documentationImprovements or additions to documentation🔨 sdksIssues related to language SDKs

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions