在 Python 中导入 Torch 时如何解决 OSError [英] How to solve the OSError while Importing torch in Python

查看:107
本文介绍了在 Python 中导入 Torch 时如何解决 OSError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

信息:

  • 操作系统:Windows 8.1 64 位
  • Python:3.7.3 64 位
  • Anaconda:64 位

议程:

确保 python -c "import torch" 工作没有任何错误.

To make sure python -c "import torch" works without any errors.

过程:

我已经使用 conda create -n myenv

在此之后,我非常困难地进一步安装了conda install pytorch torchvision cudatoolkit -c pytorch

After which with great difficulty I have further installed conda install pytorch torchvision cudatoolkit -c pytorch

执行上述命令时,由于HTTPRequest失败,中途中断

When the above command was executed, it was interrupted midway due to HTTPRequest failure

在几次这样的失败之后,我使用 conda install pytorch -c pytorch

After several such failures, I have installed pytorch using conda install pytorch -c pytorch

当我输入 python -c "import torch" 我得到如下所示的 OSError

When I type python -c "import torch" I get OSError like the one below

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\sanpj\.conda\envs\myenv\lib\site-packages\torch\__init__.py", line 42, in <module>
    import numpy as _np  # noqa: F401
  File "C:\Users\sanpj\AppData\Roaming\Python\Python37\site-packages\numpy\__init__.py", line 142, in <module>
    from . import core
  File "C:\Users\sanpj\AppData\Roaming\Python\Python37\site-packages\numpy\core\__init__.py", line 23, in <module>
    WinDLL(os.path.abspath(filename))
  File "C:\Users\sanpj\.conda\envs\myenv\lib\ctypes\__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application

但输出不应如此.

当我输入 python 时,我得到一些如下所述的信息

When I type in python, I get some information as mentioned below

Python 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.

推荐答案

解决了!

实际上,我降级到旧版本的torch、torchvision &也麻木了.这实际上解决了这个问题.

Actually, I downgraded to older versions of torch, torchvision & numpy as well. That actually solved this issue.

这篇关于在 Python 中导入 Torch 时如何解决 OSError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆