当前位置:   article > 正文

配置好torch环境后,import torch,torchvision,numpy却报错_please note and check the following: * the python

please note and check the following: * the python version is: python3.7 from

配置好torch环境后,import torch,torchvision,numpy却报错

报错内容

1、import torch

Please note and check the following:

  * The Python version is: Python3.7 from "D:\anaconda\envs\qr_env\python.exe"
  * The NumPy version is: "1.19.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: DLL load failed: 找不到指定的模块。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

2、import torchvision

Traceback (most recent call last):
  File "D:/qr_project/encoder/test.py", line 1, in <module>
    import torchvision
  File "D:\anaconda\envs\qr_env\lib\site-packages\torchvision\__init__.py", line 5, in <module>
    from torchvision import models
  File "D:\anaconda\envs\qr_env\lib\site-packages\torchvision\models\__init__.py", line 1, in <module>
    from .alexnet import *
  File "D:\anaconda\envs\qr_env\lib\site-packages\torchvision\models\alexnet.py", line 1, in <module>
    import torch
  File "D:\anaconda\envs\qr_env\lib\site-packages\torch\__init__.py", line 189, in <module>
    from torch._C import *
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe0 in position 0: invalid continuation byte

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

3、import numpy

Traceback (most recent call last):
  File "D:\anaconda\envs\qr_env\lib\site-packages\numpy\core\__init__.py", line 22, in <module>
    from . import multiarray
  File "D:\anaconda\envs\qr_env\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
    from . import overrides
  File "D:\anaconda\envs\qr_env\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ImportError: DLL load failed: 找不到指定的模块。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

note


###值得注意的是,本案例通过anaconda创建自己的环境,并且安装torch、torchvision等包,在anaconda prompt命令窗口下是可以正常导入的,而在pycharm编译器中则会报错。
###通过activate qr_env 进行自己创建的conda 环境中,输入python会显示环境中python的版本信息,再依次import,显然不会报错。这是因为在anaconda的环境下有支持import torch的dll,而在pycharm中使用的是你创建的新环境,还缺少相应支持的dll,你仅需在pycharm中添加环境变量:

解决方法–添加环境变量

在这里插入图片描述
在这里插入图片描述
添加PYTHONPATH环境变量,并将你安装的anaconda下的D:\anaconda;
D:\anaconda\Library\mingww64\bin;
D:\anaconda\Library\user\bin;
D:\anaconda\Library\bin;
D:\anaconda\Library\Scripts;D:\anaconda\Lib\site-packages
添加到Value中

问题解决啦!!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/503627
推荐阅读
相关标签
  

闽ICP备14008679号