tompal18
tompal18

Reputation: 1216

Pytorch on Windows gives ImportError

I installed Pytorch for PYthon 3.6 using pip as instructed on https://pytorch.org/.

Pytorch is installed succesfully, but when I run code, I get this:

  File "C:\Users\\PycharmProjects\chatbot-light\pytorch\rnn_attention\seq2seq_translation_tutorial.py", line 93, in <module>
    import torch
  File "C:\Users\\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\__init__.py", line 78, in <module>
    from torch._C import *
ImportError: DLL load failed: The specified module could not be found

Upvotes: 2

Views: 2834

Answers (4)

ChenZheChina
ChenZheChina

Reputation: 149

  1. Go https://anaconda.org/anaconda/intel-openmp/files
  2. Download win-64/intel-openmp-2018.0.3-0.tar.bz2
  3. Extract files under its Library/bin/ to any directory
  4. Add the directory in Step 3 to your PATH environment
  5. Restart

This solved ImportError on my computer with Windows 10 + Python 3.6.6 + PyTorch 0.4.0.

Hope it helps.

Upvotes: 1

Doug Edmunds
Doug Edmunds

Reputation: 531

This is an open Windows-related issue, see https://github.com/pytorch/pytorch/issues/4518 .

As a work-around, I installed SUSE Linux in a VirtualBox on Win10, then used the Linux pip instructions on PyTorch.org. No import error. BTW, the MS Visual Studio Code editor can be installed in Linux if you go that route.

Upvotes: 0

I remember getting an import error (I think it was the same error you show) when I installed Pytorch with CUDA.

Installing Pytorch without CUDA made the error go away.

conda install pytorch-cpu -c pytorch
pip3 install torchvision

The upshot is that you can only run it on your CPU, not a GPU, which is an issue if you're already dealing with complex models and huge datasets, but shouldn't matter too much if you're just starting to tinker with Pytorch.

Upvotes: -1

jabalazs
jabalazs

Reputation: 1264

Pytorch devs recommend installing Pytorch using Anaconda.

Since Anaconda deals with all the dependencies you shouldn't have any DLL-related problems after installing Pytorch with it.

Upvotes: 2

Related Questions