【问题标题】:Problems getting Visual Studio and python to load conda modules让 Visual Studio 和 python 加载 conda 模块的问题
【发布时间】:2020-07-06 01:43:02
【问题描述】:

我对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 代码的说明,但没有针对 Visual Studio,所以我有点不知道该怎么做。

我可以从 anaconda 提示符运行我的 python 文件,但不能从 Visual Studio 中运行。 我也用 Python 3.8 进行了测试,结果是一样的。

任何帮助将不胜感激。

【问题讨论】:

  • 您是否尝试过使用 official instructions 安装 PyTorch?
  • 这个问题不是 PyTorch 独有的,使用 conda 的说明会产生相同的结果。

标签: python numpy conda visual-studio-2019


【解决方案1】:

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

我们目前的假设是(在 Windows 和/或 Visual Studio 中)引入了一些新的安全功能,这些功能改变了环境变量的使用方式,以防止“巨大的安全风险”。

Anaconda 似乎无法很好地使用这些安全设置,因此 Visual Studio 无法加载某些模块。他引用了这个问题https://github.com/conda/conda/issues/9796

他提到较新的 python 3.8 对此有一些解决方法,但对我来说这并没有改变任何东西。

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

【讨论】:

    猜你喜欢
    • 2020-02-29
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 2013-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多