Search code examples
pythonpytorchpython-module

Python not finding torch


I want to use deepsaber. For that I have to Install Torch.

I did this using pip install torch torchvision.

After running cd scripts/generation and ./script_generate.sh [path to song] python tells me:

Traceback (most recent call last):
  File "generate_stage1.py", line 16, in <module>
    from models import create_model
  File "/home/server/deepsaber/models/__init__.py", line 2, in <module>
    from .base_model import BaseModel
  File "/home/server/deepsaber/models/base_model.py", line 2, in <module>
    import torch
ModuleNotFoundError: No module named 'torch'
Traceback (most recent call last):
  File "generate_stage2.py", line 16, in <module>
    from models import create_model
  File "/home/server/deepsaber/models/__init__.py", line 2, in <module>
    from .base_model import BaseModel
  File "/home/server/deepsaber/models/base_model.py", line 2, in <module>
    import torch
ModuleNotFoundError: No module named 'torch'

using import torch works like a charm when using python

any ideas of what I can do?

The repos says:

pytorch (installed as torch or via https://pytorch.org/get-started/locally/)


Solution

  • Most likely you installed torch using Python 2, while script_generate.sh uses Python 3 (see here):

    # [...]
    py=python3
    # [...]
    

    Try to run pip3 install torch torchvision or python3 -m pip install torch torchvision. Also, check if import torch works when using python3.