让Visual Studio和python加载conda模块时出现问题

2024-04-18 22:03:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我对python有些陌生,我正在尝试学习一些机器学习

目前,我正在尝试在python 3.7中使用两个模块,Torch和Numpy,我正在尝试使用Visual Studio 2019

我使用以下命令设置了一个anaconda3环境

conda create -n myenv python pytorch numpy numpydoc
conda activate myenv

在VS中,我已选择此作为要使用的环境。见screenshot

但是我无法运行我的程序,我收到了这个错误

  Message=

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.7 from "C:\Users\Djod\anaconda3\envs\myenv\python.exe"
  * The NumPy version is: "1.18.5"

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: The specified module could not be found.

  Source=C:\Users\Djod\source\repos\Pytorch-test\Pytorch-test\run.py
  StackTrace:
  File "C:\Users\Djod\source\repos\Pytorch-test\Pytorch-test\run.py", line 2, in <module>
    import numpy as np

本指南中有一些关于Eclipse和VS代码的说明,但不适用于VisualStudio,所以我有点纠结于该怎么做

我可以在anaconda提示符下运行python文件,但不能在VisualStudio中运行。 我还使用Python 3.8进行了测试,情况也是如此

任何帮助都将不胜感激


Tags: andthetestnumpy环境pytorchthisconda
1条回答
网友
1楼 · 发布于 2024-04-18 22:03:39

我刚刚与一位微软开发人员进行了长时间的讨论

我们目前的假设是(在windows和/或Visual studio中)引入了一些新的安全特性,这些特性改变了环境变量的使用方式,以防止“大规模安全风险”

Anaconda似乎无法很好地使用这些安全设置,因此visual studio无法加载某些模块。他提到了这个问题

他提到较新的Python3.8对此有一些改进,但对我来说,这并没有改变任何事情

目前我的解决方案是不使用conda,而是通过pip安装我需要的所有模块。 因为我可以从anaconda终端运行python文件,所以其他IDE可能工作得很好,尽管我没有测试任何IDE

相关问题 更多 >