当前位置: 代码网 > it编程>前端脚本>Python > anaconda创建了虚拟python环境,且安装了pytorch,但是pycharm中import torch运行时报错

anaconda创建了虚拟python环境,且安装了pytorch,但是pycharm中import torch运行时报错

2024年07月31日 Python 我要评论
点击Edit Configurations->Environment variables->文件图标->输入conda配置的Python环境路径C:\Users\tashi\.conda\envs\test1\Library\bin。Original error was: DLL load failed while importing _multiarray_umath: 找不到指定的模块。定位发现,是因为新创建的虚拟python环境的路径()没有加到pycharm环境变量中。

报错如下:

c:\users\tashi\.conda\envs\test1\python.exe d:\project\python\transformer\main.py 
c:\users\tashi\.conda\envs\test1\lib\site-packages\numpy\__init__.py:127: userwarning: mkl-service package failed to import, therefore intel(r) mkl initialization ensuring its correct out-of-the box operation under condition when gnu openmp had already been loaded by python process is not assured. please install mkl-service package, see http://github.com/intelpython/mkl-service
  from . import _distributor_init
traceback (most recent call last):
  file "c:\users\tashi\.conda\envs\test1\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
    from . import multiarray
  file "c:\users\tashi\.conda\envs\test1\lib\site-packages\numpy\core\multiarray.py", line 10, in <module>
    from . import overrides
  file "c:\users\tashi\.conda\envs\test1\lib\site-packages\numpy\core\overrides.py", line 8, in <module>
    from numpy.core._multiarray_umath import (
importerror: dll load failed while importing _multiarray_umath: 找不到指定的模块。

during handling of the above exception, another exception occurred:

traceback (most recent call last):
  file "c:\users\tashi\.conda\envs\test1\lib\site-packages\numpy\__init__.py", line 130, in <module>
    from numpy.__config__ import show as show_config
  file "c:\users\tashi\.conda\envs\test1\lib\site-packages\numpy\__config__.py", line 4, in <module>
    from numpy.core._multiarray_umath import (
  file "c:\users\tashi\.conda\envs\test1\lib\site-packages\numpy\core\__init__.py", line 50, in <module>
    raise importerror(msg)
importerror: 

important: please read this for advice on how to solve this issue!

importing the numpy c-extensions failed. this error can happen for
many reasons, often due to issues with your setup or how numpy was
installed.

we have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

please note and check the following:

  * the python version is: python3.9 from "c:\users\tashi\.conda\envs\test1\python.exe"
  * the numpy version is: "1.26.4"

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 while importing _multiarray_umath: 找不到指定的模块。


the above exception was the direct cause of the following exception:

traceback (most recent call last):
  file "d:\project\python\transformer\main.py", line 5, in <module>
    import torch
  file "c:\users\tashi\.conda\envs\test1\lib\site-packages\torch\__init__.py", line 1215, in <module>
    from .storage import _storagebase, typedstorage, _legacystorage, untypedstorage, _warn_typed_storage_removal
  file "c:\users\tashi\.conda\envs\test1\lib\site-packages\torch\storage.py", line 14, in <module>
    import numpy as np
  file "c:\users\tashi\.conda\envs\test1\lib\site-packages\numpy\__init__.py", line 135, in <module>
    raise importerror(msg) from e
importerror: error importing numpy: you should not try to import numpy from
        its source directory; please exit the numpy source tree, and relaunch
        your python interpreter from there.

process finished with exit code 1

定位发现,是因为新创建的虚拟python环境的路径(c:\users\tashi\.conda\envs\test1\library\bin)没有加到pycharm环境变量中。

解决方法:
点击edit configurations->environment variables->文件图标->输入conda配置的python环境路径c:\users\tashi\.conda\envs\test1\library\bin

解决后再运行不再报错,效果如下:

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com