8:00 PM
0
Q: No module named ‘torch._custom_ops’ in Jupyter Notebooks

EnigmaticBaconI'm not sure if this is the right place to ask, but I just installed cuda tools to run some GPU-based machine learning stuff on my computer, and I'm running into an issue importing torch. I'm on Ubuntu 22.04 When I run nvcc -V my output is: nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005...

 
Thanks for responding :) That first link you posted leads to your personal profile. Also, I have a pip environment (not conda). I tried adding %pip install -c torch torchvision torchaudio to my notebook to no avail (getting the error ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'torch') and magic %pip3 wasn't found either
 
"I was able to find torch._custom_ops myself, so I know it exists, but I'm not sure why it isn't working in Jupyter Notebook?" Things like this usually mean you installed it somewhere on the system; however, not in the place Jupyter is looking. I gave some advice for a different package here yesterday. You can probably combine that with some more specific, yet older advice ....
<continued> here.
"%pip install -c torch torchvision torchaudio"???? You are mixing and matching in the wrong way. -c torch comes from conda setting the torch channel. The two package managers have different syntax. You want to start with %pip install torch based on here. Then looks like pip install torchvision maybe. However, I know you are saying you are using pip here. And it may work given pip is listed here; however, pip cannot work at the level of doing things to your computer that Anaconda/conda can. Since ...
 
Should I be using conda instead of pip then? I tried %pip install torch and get a long list of "Requirements already satisfied" which makes sense because I have torch on my local machine and am running the notebook locally as well. Thanks for being patient Wayne
 
<continued> you want to do GPU stuff that involves hardware, pip may not be to do enough on your system to get you there. Be aware thought that using the Anaconda Distribution/conda adds another layer for your to learn to use it correctly. You'll want to read the Getting Started if you go that route.
 
It sounds like that's what your suggestion is :) I'll try that and let you know how it goes. Thanks Wayne
 
8:00 PM
If torch was installed correctly then importing it should not give you an error. When you say you import it you don't provide what you actually do to try that leads to that error ModuleNotFoundError: ... 'torch' is not a package? You should update your post to include that. Always have what you did and what you go. Not just half the story.
 
Hey there Wayne. StackOverflow recommended I move this to chat. I hope that's okay.
My notebook only has one line: "import torch
"
So unfortunately there isn't much more I'm trying to do at the moment
 
Oh okay. I do note that even the PyPI page there for torch says for Linux to use Conda to get the depenencies.
 
You got it. Thank you again for taking the time to walk me through this. I just got out of school and am now working a job and feel way out of my depth, so I really appreciate it
I'll try the Conda :)
 
I would suggest creating a separate environment where you'll use torch. (Read the Getting started to get a sense of this.) After you create the new environment. You'll need to connect Jupyter to it. The bottom of here has the steps to do that for adding a different version of Python. (That was back when Anaconda probably came with 3.4 or 3.5 in the base install and it was illustrating adapting it to making a conda environment for Python 3.6.)
So you'll need to adapt the packages to what you need. The overall process will be similar. Related to this, also see here and here.
As we dicussed earlier, the code here is already towards what you'll need: conda install pytorch torchvision -c pytorch.
 
 
2 hours later…
10:37 PM
Unfortunately, it seems doing the same thing in conda still results in the same error, but only in Jupyter Notebook. If I'm just coding away in a .py, there's no problem regardless of whether I'm in the conda env or not
 
11:02 PM
Okay I got the conda env linked up to my notebook, and though it can now do %conda install I still get the same error about torch._custom_ops