question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImportError: No module named torch.autograd

See original GitHub issue

Hello all!, It seems install is ok

Requirement already satisfied: torchvision in /usr/local/lib/python3.8/dist-packages (0.8.1) Requirement already satisfied: torch==1.7.0 in /usr/local/lib/python3.8/dist-packages (from torchvision) (1.7.0) Requirement already satisfied: pillow>=4.1.1 in /usr/lib/python3/dist-packages (from torchvision) (7.2.0) Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (from torchvision) (1.19.2) Requirement already satisfied: future in /usr/lib/python3/dist-packages (from torch==1.7.0->torchvision) (0.18.2) Requirement already satisfied: typing-extensions in /usr/lib/python3/dist-packages (from torch==1.7.0->torchvision) (3.7.4.3) Requirement already satisfied: dataclasses in /usr/local/lib/python3.8/dist-packages (from torch==1.7.0->torchvision) (0.6) Guided by Installation instructions all ok except when I launch: # python run.py --input_folder /imgs/ --output_folder /imgs/output/ --GPU 0

Running Stage 1: Overall restoration Traceback (most recent call last): File "test.py", line 6, in <module> from torch.autograd import Variable ImportError: No module named torch.autograd Traceback (most recent call last): File "run.py", line 91, in <module> for x in os.listdir(stage_1_results): OSError: [Errno 2] No such file or directory: '/imgs/output/stage_1_restore_output/restored_image'

root@DESKTOP-H0VF09L:/home/akenateb/Bringing-Old-Photos-Back-to-Life# python Python 2.7.18 (default, Apr 20 2020, 20:30:41) [GCC 9.3.0] on linux2 ` What I am doing wrong? Thanks in advance.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
nobreakcommented, Jan 4, 2021

I am experiencing this problem on my Mac Catalina. Any suggestions? pip3 shows torch and torchvision packages but I am still getting a torch.autograd error.

For me the same on MacOS Catalina, any news ?

I updated to python 3.8.7 and added to ~/.bash_profile the alias ‘alias python=python3’ I also installed the related frameworks

Requirement already satisfied: torch in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from -r requirements.txt (line 1)) (1.7.1) Requirement already satisfied: torchvision in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from -r requirements.txt (line 2)) (0.8.2)

UPDATE: I found a solution now for my case. I found out that the on terminal called run.py script was working with python3 but all other py scripts which was called by code was running with python2. I don’t know why (i changed the alias in ~/.bash_profile and restartet the terminal session, but still this issue. So my solution was to just change in Global/test.py all “python …” calls to python3.

Not it runs, but on mac i have to switch off the use of GPU by “–gpu_ids -1” - there is no support for it (error: “AttributeError: module ‘torch._C’ has no attribute ‘_cuda_setDevice’”)

0reactions
zhonglaobancommented, Aug 1, 2022

I am experiencing this problem on my Mac Catalina. Any suggestions? pip3 shows torch and torchvision packages but I am still getting a torch.autograd error.

For me the same on MacOS Catalina, any news ?

I updated to python 3.8.7 and added to ~/.bash_profile the alias ‘alias python=python3’ I also installed the related frameworks

Requirement already satisfied: torch in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from -r requirements.txt (line 1)) (1.7.1) Requirement already satisfied: torchvision in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from -r requirements.txt (line 2)) (0.8.2)

UPDATE: I found a solution now for my case. I found out that the on terminal called run.py script was working with python3 but all other py scripts which was called by code was running with python2. I don’t know why (i changed the alias in ~/.bash_profile and restartet the terminal session, but still this issue. So my solution was to just change in Global/test.py all “python …” calls to python3.

Not it runs, but on mac i have to switch off the use of GPU by “–gpu_ids -1” - there is no support for it (error: “AttributeError: module ‘torch._C’ has no attribute ‘_cuda_setDevice’”)

when the error(error: “AttributeError: module ‘torch._C’ has no attribute ‘_cuda_setDevice’”) occured. just set GPU to ‘-1’ like this --GPU -1

Read more comments on GitHub >

github_iconTop Results From Across the Web

No module named 'torch.autograd' - Stack Overflow
It seems to me that you have installed pytorch using conda. Might be you have torch named folder in your current directory.
Read more >
Python ModuleNotFoundError: No Module Named 'torch'
Quick Fix: Python raises the ImportError: No module named 'torch' when it cannot find the library torch . The most frequent source of...
Read more >
No module named 'torch' - Quora
This error usually means you have not installed the module or it isn't in your module search path: 'torch' is part of PyTorch....
Read more >
Can't import torch.nn - new installation - PyTorch Forums
I just installed PyTorch on Windows Linux Subsystem (WSL): root@TESLA:~# conda install pytorch torchvision -c soumith Fetching package metadata .
Read more >
no module named 'torch' - 腾讯云开发者社区
torch.nn.Module.named_parameters () · Python安装Pytorch(解决ModuleNotFoundError: No module named 'torch') · 广告 · 安装PyTorch后jupyter notebook中仍出现“No module ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found