Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dbaeumer opened this issue Dec 16, 2022 · 2 comments
Closed

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

dbaeumer opened this issue Dec 16, 2022 · 2 comments
Labels
OS-wasi type-bug An unexpected behavior, bug, or error

Comments

@dbaeumer
Copy link

dbaeumer commented Dec 16, 2022

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 
@dbaeumer dbaeumer added the type-bug An unexpected behavior, bug, or error label Dec 16, 2022
@brettcannon
Copy link
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).

@brettcannon brettcannon 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 Jan 13, 2023
@brettcannon
Copy link
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.
>>>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-wasi type-bug An unexpected behavior, bug, or error
Projects
No open projects
Status: Done
Development

No branches or pull requests

3 participants