So all of a sudden my code broke. Error: Unable to import torch, No module named torch
. So I attempt to install torch; error, ModuleNotFoundError: No module named 'tools.nnwrap'
. I delete my venv and re-create it, same thing. I try it outside the venv, same issue. I look up the issue, apparently I should go here. I do, try several of the install commands, with cuda, without, all broken. What do I do? Am on Arch Linux if that's relevant, maybe I broke something.

- 57
- 1
- 8
-
If you ran a ```pacman -Syu``` yesterday, it's possible it has to do with the new python release. Does a ```python3 -m venv --upgrade .``` help? – OctaveL Dec 03 '20 at 10:37
-
I did run an update recently, but updating the venv doesn't help :( – RichKat Dec 03 '20 at 14:41
-
If you're still stuck, please send your exact requirements for your venv, and I can try replicating it. I'm on the same OS – OctaveL Dec 04 '20 at 11:09
-
It's just Python 3.9. I've tried this in the venv and outside it. Nothing seems to work. All other packages seem to work. If I try to use one of the more specific commands I get something like ```ERROR: Could not find a version that satisfies the requirement torch==1.7.0+cpu (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2)``` – RichKat Dec 04 '20 at 15:03
-
Any chance you could send me your ```requirements.txt``` so I can see if I can make it work? – OctaveL Dec 04 '20 at 15:04
-
Nevermind, I can confirm I'm getting the same error if I try to install ```torch==1.7.0+cpu```. I'll look into it when I have the time – OctaveL Dec 04 '20 at 15:08
-
Thank you, but as it turns out PyTorch just doesn't work with Python 3.9 :(. I've downgraded and managed it to work now. – RichKat Dec 04 '20 at 16:45
-
I'm the one whose answer you accepted, so believe me, I know it doesn't :P – OctaveL Dec 04 '20 at 18:21
-
Ah right, my mistake :) – RichKat Dec 05 '20 at 19:02
2 Answers
https://github.com/pytorch/pytorch/issues/47116
It's a recent issue with Python 3.9, as expected: it's sadly not compatible with PyTorch as of right now (04/12/2020), and the error message isn't explicit about it. The issue is currently still open and pending, and all you can do is revert to 3.8 for the time being.

- 1,017
- 8
- 18
-
Damn, well ok, I guess I now just have to figure out how to downgrade my python – RichKat Dec 04 '20 at 15:29
If you use pip, take a pip installation link from here and replace pip
with pip3
.
This resolved my problem with No module named 'tools.nnwrap'
a few days ago.
Tested on Python 3.8.6, Windows 10
Example
Use pip3 install torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio===0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
instead of pip install torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio===0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
Edit

- 853
- 8
- 22