简体   繁体   中英

Anaconda / Pytorch - Getting error when trying to get Pytorch working

I've tried the installing Pytorch with Anaconda on a Windows 10 system but have gotten a variety of errors back with each attempt. I downloaded a windows compatible tar file of the package from https://anaconda.org/peterjc123/pytorch/files and was apparently able to get the the package installed using conda install filename.tar.bz2. By apparently, I mean that the Pytorch shows up in the list of packages available in the environment I set up for using Pytorch. But when I go to load the package I get this error:

>>> import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\conner\Anaconda3\envs\pytorch\lib\site-packages\torch\__init__.py", line 76, in <module>
    from torch._C import *
ImportError: DLL load failed: The specified module could not be found.

I also tried updating Anaconda with conda update --all which raised a relevant warning:

(pytorch) C:\Users\User 1\Downloads>conda update --all
Fetching package metadata .............
Solving package specifications:
Warning: ['Dependency missing in current win-64 channels: \n  - pytorch -> mkl >=2018'], skipping
Fetching package metadata .............
Solving package specifications:
Warning: ['Dependency missing in current win-64 channels: \n  - pytorch -> mkl >=2018'], skipping

NoPackagesFoundError: Dependency missing in current win-64 channels:
  - pytorch -> mkl >=2018

The mkl package also shows up in the list of packages connected to the pytorch environment. I interpret the error to mean that there isn't a recent enough version of mkl . Would that be correct? Any other insights or advice? I really need to get pytorch installed.

I recommend you create a new conda enviroment and try to reinstall PyTorch in this way:

To install PyTorch via Anaconda, and do not have a CUDA-capable[LINK] system or do not require CUDA, use the following conda command.

conda install pytorch-cpu torchvision-cpu -c pytorch

To install PyTorch via Anaconda, and you are using CUDA 9.0, use the following conda command:

conda install pytorch torchvision -c pytorch

CUDA 8.x

conda install pytorch torchvision cuda80 -c pytorch

CUDA 10.0

conda install pytorch torchvision cuda100 -c pytorch

#Inno

  • Since you are using Anaconda then try this : conda install pytorch -c pytorch
  • After that use this command: pip3 install torchvision
  • The pip you use has to be a pip of conda environment
  • The above commands will also install all the dependencies
  • You manually downloading the tar files won't install the depedencies
  • The above commands are mentioned on the official website : https://pytorch.org/
  • Installing packages by yourself is really painful and time-consuming... Always try to use package managers for installing packages

Based on my experiences, the reason is that Pytorch could not call your system recommended CUDA dll file, so you have to install Pytorch with exact CUDA version's dll.

To install Pytorch via Anaconda and work properly, you should choose the CUDA version for your hardware appropriately. For instance,

CUDA 9.0

conda install pytorch==1.0.1 torchvision==0.2.2 cudatoolkit=9.0 -c pytorch

CUDA 10.0

conda install pytorch==1.0.1 torchvision==0.2.2 cudatoolkit=10.0 -c pytorch

CPU Only

conda install pytorch-cpu==1.0.1 torchvision-cpu==0.2.2 cpuonly -c pytorch

If you installed CUDA and CUDA Toolkit driver correctly, you do not need to choose CUDA version manually.

I hope it could be helpful to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM