No module named 'torch'" error

I am trying to install the pytorch version1.8.0 amd i am following the steps mentioned in this link PyTorch for Jetson

The problem is i keep meeting a no module named "torch " error, when i get on the python3 setup.py install --user step

It is mention on the original post that # attempting to load torchvision from build dir will result in import error but i don’t know how to run the setup.py script outside of the torchvision directory

Hi @umuhozamariange1, are you able to run python3 -c 'import torch' ? What does pip3 show torch`? Have you installed the PyTorch wheel with pip3 first, before attempting to build torchvision?

It is mention on the original post that # attempting to load torchvision from build dir will result in import error but i don’t know how to run the setup.py script outside of the torchvision directory

This is unrelated to setup.py - it means, don’t attempt to run in a python script import torchvision when your terminal working directory has the torchvision sources under it, because Python will try to load from those uncompiled sources (instead of the one that got installed). Basically, after you run setup.py, change your working directory before testing import torchvision

If you continue facing issues getting PyTorch/Torchvision installed, the l4t-pytorch container comes with them pre-built.

i installed the PyTorch wheel with pip3 after trying to build torch vision when i realised i may have skipped the step. the went on and tried to rebuild it after correctly installing cython and numpy torch1.08 with pip3 but it still shows the same error:
Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘torch’

@umuhozamariange1 are you able to run python3 -c 'import torch' now? torchvision won’t build until you have PyTorch working first. If it doesn’t, do pip3 uninstall torch and then pip3 install one of the PyTorch wheels again. It should show up when you do pip3 show torch

hello dusty, " pip3 show torch" does give the correct results of torch installed

Name: torch
Version: 1.8.0
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: packages@pytorch.org
License: BSD-3
Location: /home/marco/.local/lib/python3.6/site-packages
Requires: dataclasses, numpy, typing-extensions
Required-by.

but when i run python3 -c ‘import torch’ i still get the error Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘torch’

this is the same error i get with all y pip3 installed packages(numpy,pyaudio,tensorflow,etc) that are found in this directory: Location: /home/marco/.local/lib/python3.6/site-packages. i checked the path with command :“echo $PATH” and it gives these results :
/home/marco/.local/bin:/home/marco/archiconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

the i tried the export PATH=$PATH: /home/marco/.local/lib/python3.6/site-packages. but still it wont work.

i have an archiconda3 environment set up and by calling python3 i get the following results:
Python 3.7.2 (default, Jan 11 2019, 18:52:21)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type “help”, “copyright”, “credits” or “license” for more information.

which shows python3.7.2 and most packages i downloaded are compatible with python3.6.9. what can i do?

Due to the confusing behavior of seeing torch listed by pip but not importable, can you disable the archiconda environment? That PyTorch wheel was for Python 3.6, it wouldn’t work under Python 3.7 which is perhaps why you aren’t able to import it?

Thank you very much, after disabling the archiconda environment, i can successfully import pytorch. the error was that archiconda was using the wrong vesrion of python as you stated.

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