bytecodealliance / componentize-py

Apache License 2.0
130 stars 13 forks source link

Matrix-math example - ImportError... #50

Closed Bandsberg closed 6 months ago

Bandsberg commented 6 months ago

Following the example of matrix-math fd5b49c I get the following error when running componentize-py -d ../../wit -w matrix-math componentize app -o matrix-math.wasm:


warning: site-packages directory not found under /home/jes/gitrepositories/wasmcloud_test/my-py-component-wasmtime16-0-0/myenv/lib
Traceback (most recent call last):
  File "/home/jes/.local/bin/componentize-py", line 8, in <module>
    sys.exit(script())
             ^^^^^^^^
AssertionError: Traceback (most recent call last):
  File "/0/app.py", line 5, in <module>
    import numpy
  File "/0/numpy/__init__.py", line 157, in <module>
    from . import random
  File "/0/numpy/random/__init__.py", line 180, in <module>
    from . import _pickle
  File "/0/numpy/random/_pickle.py", line 1, in <module>
    from .mtrand import RandomState
ImportError: dynamic module does not define module export function (PyInit_mtrand)

Caused by:
    ImportError: dynamic module does not define module export function (PyInit_mtrand)

I am using python 3.12 and have created an enviroment using virtualenv I am more experienced in Rust than python and have been unable to figure out if it is an error on my side or with the example.

dicej commented 6 months ago

Thanks for reporting this! I wasn't able to reproduce this on MacOS with Python 3.12, but I did get something similar on Linux. I'll start digging into it.

dicej commented 6 months ago

The issue I hit on Linux seems to be due to the issue addressed by https://github.com/bytecodealliance/wasm-tools/pull/1341. Updating to the main branch of wasm-tools fixed it. I'll open a PR shortly to update the wasm-tools dep and then publish a 0.9.1 release once CI is finished.

In my case, the function it was complaining about was PyInit__multiarray_umath rather than PyInit_mtrand, but I suspect the underlying cause was the same.

dicej commented 6 months ago

@Bandsberg when you have a chance, please try again with componentize-py 0.9.1 and let me know if you still have trouble.

Bandsberg commented 6 months ago

@dicej Thank you for looking in to this issue! With this fix the example now works for me (I am using Ubuntu 22.04 lts).