You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python WASM-WASI can't be executed from a different directory than root #100307
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
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).
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
❯ wasmtime --mapdir /usr/local/lib::lib python.wasmPython 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 wasiType "help", "copyright", "credits" or "license" for more information.>>>
Activity
brettcannon commentedon Jan 13, 2023
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
/libfor the stdlib, so mounting to/usrwhere thelibdirectory of a build is will cause that to fail as that would make/usr/libbe 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).
[-]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[/+]brettcannon commentedon Mar 28, 2023
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: