Skip to content

Python WASM-WASI can't be executed from a different directory than root #100307

Closed

Description

@dbaeumer

Bug report

  • install wasmtime (I used 3.0.1)
  • download Python-3.11.0-wasm32-wasi-16.zip
  • extract it into a directory
  • cd into that directory
  • run python using the following command line wasmtime run --mapdir /::. ./python.wasm
    Observe: everything works as expected. You end up in a REPL
  • try to 'mount' the python installation into a different directory (e.g. /usr) by running wasmtime run --mapdir /usr::. --env PYTHONHOME=/usr/lib/python3.11 ./python.wasm
    Observe: you get
Exception ignored error evaluating path:
Traceback (most recent call last):
  File "<frozen getpath>", line 471, in <module>
OSError: [Errno 76] Capabilities insufficient
Fatal Python error: error evaluating path
Python runtime state: core initialized

Current thread 0x00000000 (most recent call first):
  <no Python frame>

I was not able to successfully execute Python when mounting the installation directory to something different than /

Your environment

  • wasmtime 3.0.1
  • Python-3.11.0-wasm32-wasi-16.zip
  • WSL2 running 5.15.79.1-microsoft-standard-WSL2
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.5 LTS
Release:        20.04
Codename:       focal 

Activity

  1. brettcannon commented on Jan 13, 2023

    @brettcannon
    Member

    This is caused because there's logic within Python to know where to look for the stdlib that gets baked in. As of right now that logic looks for /lib for the stdlib, so mounting to /usr where the lib directory of a build is will cause that to fail as that would make /usr/lib be where the stdlib resides which isn't where Python will go looking.

    There are two possible solutions to this annoyance. One is to patch things up to be relative to the binary location somehow. The other is to embed the pure Python code into the binary. The latter would require making sure there's a way to map to the source, if available, so that tracebacks are a bit nicer (otherwise the source code lines won't show up).

  2. changed the title [-]Python WASM-WASI can't be executed from a different directory than root.[/-] [+]Python WASM-WASI can't be executed from a different directory than root[/+] on Jan 13, 2023
  3. brettcannon commented on Mar 28, 2023

    @brettcannon
    Member

    With the latest build for CPython 3.11.2 I have up at https://github.com/brettcannon/cpython-wasi-build this is no longer a problem:

    ❯ wasmtime --mapdir /usr/local/lib::lib python.wasm
    Python 3.11.2 (tags/v3.11.2-dirty:878ead1, Mar 27 2023, 22:47:44) [Clang 14.0.4 (https://github.com/llvm/llvm-project 29f1039a7285a5c3a9c353d05414 on wasi
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
  4. moved this from Todo to Done in WASI to tier 2on Jun 3, 2023
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

    OS-wasitype-bugAn unexpected behavior, bug, or error

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions