简体   繁体   中英

Encounter Error after installing Pytorch using pip in python3.5

I am using windows 10 OS with Python 3.5.
I am trying to run a program related to torch . So I installed Pytorch with the help of the instructions specified on their website: Pytorch installation

See the following image for selection of the downloadable:

pytorch安装

I installed it using :

pip install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp35-cp35m-win_amd64.whl 
pip install torchvision

I have encountered the following error:

Error
Traceback (most recent call last):
  File "C:\Python35\lib\site-packages\twisted\trial\runner.py", line 701, in findByName
    __import__(name)
  File "C:\Users\aims\Desktop\CNN\source\cnn4matrix.py", line 4, in <module>
    import torch
  File "C:\Python35\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.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python35\lib\site-packages\twisted\trial\runner.py", line 803, in loadByName
    return self.suiteFactory([self.findByName(name, recurse=recurse)])
  File "C:\Python35\lib\site-packages\twisted\trial\runner.py", line 704, in findByName
    return self.loadFile(_name, recurse=recurse)
  File "C:\Python35\lib\site-packages\twisted\trial\runner.py", line 674, in loadFile
    module = SourceFileLoader(name, fileName).load_module()
  File "<frozen importlib._bootstrap_external>", line 385, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 806, in load_module
  File "<frozen importlib._bootstrap_external>", line 665, in load_module
  File "<frozen importlib._bootstrap>", line 268, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 693, in _load
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "C:\Users\aims\Desktop\CNN\source\cnn4matrix.py", line 4, in <module>
    import torch
  File "C:\Python35\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.

After searching a lot I couldn't found anything related. Instead I found that I have tried: Reinstall with upgrade mode, the numpy library.

Please let me know what I can try.

EDITED:

This is the scenario for me: I have install torch from the website instructions and then opened python terminal. just written import torch and the issue is what I got. Have a look at the image: https://ibb.co/fL53HT

Please see this following thread: https://github.com/pytorch/pytorch/issues/574

Basically, the problem might be that you have a folder called 'torch' in the same directory from where you are invoking python. So instead of the pytorch library being loaded, the folder named 'torch' is being picked up.

Do this: cd .. (to change directory), and then start python and import torch, it should work.

the one solution here if doesn't work after reinstalling Anaconda, then you can use sth. like Dependency Walker, open [Anaconda PATH]\\Lib\\site-packages\\torch\\lib\\_C.pyd
to detect what's wrong there.

and the other solution is caused by the directory torch which is generated in the same directory by compiling the source. try to simply changing the directory before open python.

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