singlestore-labs / python-wasi

Utilities for building CPython for the WASI platform
Apache License 2.0
96 stars 14 forks source link

Can't execute hello.py file #11

Closed LijieZhang1998 closed 1 year ago

LijieZhang1998 commented 1 year ago

Hi, I followed the instruction to build wasi-python. It's working. My built file is wasi-python3.13.wasm. I created a sample hello python file(just one line print('hello')) in the docker container. Then I ran this command to execute it in the docker container.

wasmtime run --mapdir=/opt/wasi-python/lib/python3.13::/
opt/wasi-python/lib/python3.13 --mapdir=/tmp::/tmp -- wasi-python3.13.wasm /path/to/hello.py

I got an error wasi-python3.13.wasm: can't open file '/path/to/hello.py': [Errno 76] Capabilities insufficient.

Does anybody have any idea? As you may see, my python version is 3.13.

Appreciate your help.

kesmit13 commented 1 year ago

Try adding -B before /path/to/hello.py. It's likely that Python is trying to compile the standard library to .pyc files, which it may not have permission to do.

LijieZhang1998 commented 1 year ago

I tried this. It still failed with the same error.


wasmtime run --mapdir=/opt/wasi-python/lib/python3.13::/
opt/wasi-python/lib/python3.13 --mapdir=/tmp::/tmp -- wasi-python3.13.wasm -B /path/to/hello.py
kesmit13 commented 1 year ago

I see now. You need to add /path/to to your directory mappings. Try adding --mapdir=/::/path/to.

LijieZhang1998 commented 1 year ago

ahh. I use --dir to make it work. This is the workable command, where testfiles folder is located in the same folder as wasi-python3.13.wasm is.

wasmtime run --mapdir=/opt/wasi-python/lib/python3.13::/opt/wasi-python/lib/python3.13 --dir=. -- wasi-python3.13.wasm -B ./testfiles/hello.py

Thank you very much.

kesmit13 commented 1 year ago

Just as a side note, while this repo is still functional, there is more formal work being done on creating Python Wasm components. You may want to check out https://github.com/dicej/componentize-py.