From torch._C import * : No Torch._C!

When I call, “import torch,” I get:
“ImportError: DLL load failed while importing C: The specified module could not be found," caused in the file:
"torch_init
.py”
by the line:
"from torch._C import * "
In my file structure, there is no “Torch._C.” Nor is there a folder “csrc.”
I use Windows 10, 64 bit. I installed PyTorch with:
“pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
(Stable1.4, Windows, Python, Cuda=none).
I have the same failure when installing on Python 3.6.1 and on Python 3.8,1.
I have fought this problem for a week, now. I have seen this problem addressed in many places on the internet. Help would be appreciated. Is there something missing from my computer, some ‘C’ capability, that I need to install?

You would get this error e.g. if your current working directory is inside the pytorch folder (after building from source), so make sure to open the Python terminal somewhere else.

Also, this might happen, if the installation was unsuccessful or if you have multiple pytorch installations in your current environment (although the error might look different).

How did you install PyTorch and could you create a new environment and reinstall it?

I installed PyTorch by opening a Windows command prompt. In it, I pasted, "pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html” , (as I said in my original post). The Windows PATH commands would then cause pip to run in the Python/Python38/Scripts folder. It successfully(?) installed PyTorch and TorchVision in Python/Python38/Lib/sitepackages, in the same folder as the sci-py, numpy, sklearn packages.
I had this problem when I only had Python 3.6.1 installed. I reinstalled PyTorch many times. I then installed Python 3.8, to see if PyTorch would work with that, and I have the same problem. I start Python from the Windows IDLE program which is installed with Python. But even if I start Python from a Windows command prompt and type “import torch,” I get the same failure.
I’m not sure what you mean when you say, “create a new environment,” or “your current working directory is inside the pytorch folder.” But, my Python file structure looks good to me.It got me through 20 data science courses from DataCamp, and books like “Deep Learning from Scratch.”

Could you post the output log of the pip install ... command?

Which Python distribution did you use? Anaconda or just Python from the official site? If the latter one is used, please install VS 2017 Redist on your own. https://aka.ms/vs/16/release/vc_redist.x64.exe Also please install some other dependencies through pip install intel-openmp mkl and then restart the command prompt.

2 Likes

Your solution worked! Thank you so very much.