No module named 'torch'

Hi :wave:

Cant deploy my app 'cause i get

ModuleNotFoundError: No module named 'torch' but i have torch>=1.7 in the requirements.txt

Repo: GitHub - angelicaba23/app-super-resolution at dev


Hi :wave: @Kanak !

Sure! im sending the log file.
repo: GitHub - angelicaba23/app-super-resolution at prod

this is the setup.py i guess…

I dont know if is there any other way to have the package installed to use it, i’ve tried with:

  • cloning the repo inside mine but only keeping the ‘basicsr’ folder
  • still importing the same way as it was(from basicsr.utils import imwrite)

but i get this…


and inside the code is this but i dont know how to do it (set BASICSR_JIT=True during running) bc i use the env var but dosent work.

Unfortunately, it’s not clear to me how to solve this issue, as it looks like a package calls out to a subprocess to install torch, which is a non-standard Python way of handling installs which we haven’t planned for on Streamlit Cloud.

Having the same issue when installing torch-scatter, torch-sparse deps:

Collecting torch-scatter==2.0.9

  Downloading torch_scatter-2.0.9.tar.gz (21 kB)

  Preparing metadata (setup.py): started

  Preparing metadata (setup.py): finished with status 'error'

  error: subprocess-exited-with-error

  

  × python setup.py egg_info did not run successfully.

  │ exit code: 1

  ╰─> [6 lines of output]

      Traceback (most recent call last):

        File "<string>", line 2, in <module>

        File "<pip-setuptools-caller>", line 34, in <module>

        File "/tmp/pip-install-4sqktldq/torch-scatter_5ebc64e92a104e449b5d280d71aa04cd/setup.py", line 8, in <module>

          import torch

      ModuleNotFoundError: No module named 'torch'

      [end of output]

  

  note: This error originates from a subprocess, and is likely not a problem with pip.

error: metadata-generation-failed


× Encountered error while generating package metadata.

╰─> See above for output.


note: This is an issue with the package mentioned above, not pip.

hint: See above for details.

According to the project page you are supposed to install a binary wheel:

To install the binaries for PyTorch 1.13.0, simply run

pip install torch-scatter -f https://data.pyg.org/whl/torch-1.13.0+${CUDA}.html

where ${CUDA} should be replaced by either cpu, cu116, or cu117 depending on your PyTorch installation.

This means you have to add two lines to your requirements.txt (adjust according to your pytorch installation):

-f https://data.pyg.org/whl/torch-1.13.0+cpu.html
torch-scatter
2 Likes

Thanks. @Goyo It has been fixed.

I face the same problem when torch-sparse in my code too,have you fix it?

See previous answer from @Goyo and here:

https://github.com/rusty1s/pytorch_sparse#binaries

thank you ,it did make some differences!

Have you tried to append these lines to your requirements.txt file:

torch==1.12.1

torch-geometric==2.1.0
-f https://data.pyg.org/whl/torch-1.12.1+cpu.html
torch-scatter==2.0.9
-f https://data.pyg.org/whl/torch-1.12.1+cpu.html
torch-sparse==0.6.16

I ran streamlit run but it sill same error ModuleNotFoundError: No module named ‘torch’

I had the same error, in the end I had to add torchvision to requirements.txt and it was working.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.