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

ModuleNotFoundError: No module named 'torch' #2

Open
su3 opened this issue May 10, 2024 · 5 comments
Open

ModuleNotFoundError: No module named 'torch' #2

su3 opened this issue May 10, 2024 · 5 comments

Comments

@su3
Copy link

su3 commented May 10, 2024

I wrote a simple Python program for testing. After execution, I got:

wasmer ran.wasm 

Traceback (most recent call last):
  File "./ran.py", line 1, in <module>
ModuleNotFoundError: No module named 'torch'

The code is as follows:

import torch

def main():
    n = torch.rand(3, 4)
    print("Hello", n)


if __name__ == "__main__":
    main()

Here's the compilation process:

py2wasm ran.py -o ran.wasm

py2wasm: Using wasi-sdk from /Users/user/miniconda3/lib/python3.11/site-packages/nuitka/wasi-sdk/21/sdk-Darwin
Nuitka-Options: Used command line options: ran.py --standalone --static-libpython=yes --disable-ccache --lto=yes
Nuitka-Options: --output-dir=/Users/user/miniconda3/lib/python3.11/site-packages/nuitka/__py2wasm --output-filename=output.wasm --remove-output
Nuitka: Starting Python compilation with Nuitka '2.6.3' on Python '3.11' commercial grade 'not installed'.
Nuitka: Completed Python level compilation and optimization.                             
Nuitka: Generating source code for C backend compiler.
Nuitka: Running data composer tool for optimal constant value handling.
Nuitka: Running C compilation via Scons.
Nuitka-Scons: Backend C compiler: ~/miniconda3/lib/python3.11/site-packages/nuitka/wasi-sdk/21/sdk-Darwin/bin/clang (clang 17.0.6).
Nuitka-Scons: Backend linking program with 7 files (no progress information available for this stage).
clang: warning: argument unused during compilation: '-headerpad_max_install_names' [-Wunused-command-line-argument]
Nuitka: Removing build directory '/Users/user/miniconda3/lib/python3.11/site-packages/nuitka/__py2wasm/ran.build'.
Nuitka: Created binary that runs on macOS 11.1 (arm64) or higher.
Nuitka: Successfully created '/Users/user/miniconda3/lib/python3.11/site-packages/nuitka/__py2wasm/ran.dist/output.wasm'.
py2wasm: File created successfully: ran.wasm

It works fine when compiled with Nuitka.

python -m nuitka ran.py

 ./ran.bin
Hello tensor([[8.8891e-02, 1.0744e-02, 1.4557e-01, 2.1542e-01],
        [5.2137e-01, 6.6914e-03, 8.2231e-04, 8.7954e-01],
        [1.8713e-01, 3.6060e-02, 4.5850e-01, 3.1474e-01]])

The current environment is:

python -m nuitka --version

2.2.1
Commercial: None
Python: 3.11.5 (main, Sep 11 2023, 08:31:25) [Clang 14.0.6 ]
Flavor: Anaconda Python
Executable: /Users/user/Code/env/venv/bin/python
OS: Darwin
Arch: arm64
macOSRelease: 14.4.1
Version C compiler: /usr/bin/clang (clang 15.0.0).

Not sure what went wrong?

@artsiommiksiuk
Copy link

I'm having the same issues, just different imported modules can't be found.

@artsiommiksiuk
Copy link

artsiommiksiuk commented May 24, 2024

Okay, I think I found an issue. If you have some dependencies make sure you running compilation from the same env. In my case, I had venv in one place, but because of requirement to run py2wasm from python 11 I decided to separately call it outside venv. And that resulted that none of the dependencies were found. After I resetup whole venv with python 11 and launched compilation from this venv (with all installed dependencies) compilation now found a lot of files

Nuitka-Scons: Backend linking program with 1842 files (no progress information available for this stage)., instead of just a few.

@su3 So, make sure you running everything from the same env. Because in your log it says only 7 files found for linking, which I think is a mistake (I believe pytorch has more than 7 c level dependencies).

@su3 su3 closed this as completed Jun 3, 2024
@su3 su3 reopened this Jun 3, 2024
@su3
Copy link
Author

su3 commented Jun 3, 2024

@su3 So, make sure you running everything from the same env. Because in your log it says only 7 files found for linking, which I think is a mistake (I believe pytorch has more than 7 c level dependencies).

I confirm that I tested and compiled in the same environment. Running the Python script directly works without any issues.

@syrusakbary
Copy link
Member

Hey @su3 , running torch (and any other native python modules that rare using C) in WASI is not yet supported.

We are working on adding them as part of WASIX, and doin that sholud solve this issue

@cihansakman
Copy link

Hello @syrusakbary do you have any updates on running python native extenisons?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants