简体   繁体   English

从 Visual Studio Code 调试 Python - 导入 Numpy

[英]Debug Python from Visual Studio Code - Importing Numpy

import numpy
print "asdf"

When I try to debug/run the above Python code in Visual Studio Code I get the following error (Using OSX)当我尝试在 Visual Studio Code 中调试/运行上述 Python 代码时,出现以下错误(使用 OSX)

ImportError, cannot import name float96 ImportError,无法导入名称 float96

What is the resolution?分辨率是多少?

I have installed python from the python website.我已经从 python 网站安装了 python。 Tried to run after installing from brew too but no effect.也尝试从 brew 安装后运行但没有效果。

EDIT编辑

The problem is with all imports for Visual Studio问题在于 Visual Studio 的所有导入

this is an issue with the debugger, in the manner in which it loads the modules and such import errors can be safely ignored. 这是调试器的一个问题,它以加载模块的方式,可以安全地忽略这样的导入错误。 To ignore these errors, please go into the launch.json file and edit it as follows (to add the section to ignore the "ImportError"): 要忽略这些错误,请进入launch.json文件并按如下所示进行编辑(添加部分以忽略“ImportError”):

{ "name": "Python", "type": "python", "request": "launch", "stopOnEntry": true, "program": "${file}", "debugOptions": [ "WaitOnAbnormalExit", "WaitOnNormalExit", "RedirectOutput" ], "exceptionHandling": { "ignore": ["ImportError"] } },

In my case, the problem was that vscode was using the python (v2) interpreter but I had installed the module using python3. 在我的情况下,问题是vscode使用python(v2)解释器,但我使用python3安装了模块。

I fixed this modifying the launch.json file and specifying the pythonPath for python3, as explained here . 我解决了这个修改launch.json文件并指定PYTHONPATH为python3,如解释在这里

Re-insatlling python extension solved my issue. 重新插入python扩展解决了我的问题。 It was not a problem of configuration after all. 毕竟这不是配置问题。

https://code.visualstudio.com/docs/languages/python_c https://code.visualstudio.com/docs/languages/python_c

Tip: Don Jayamanne's Python extension gives you the option of using three different linters - Pylint, Pep8, and Flake8. 提示:Don Jayamanne的Python扩展使您可以选择使用三种不同的线程--Pylint,Pep8和Flake8。 See the wiki for more details. 有关更多详细信息,请参阅Wiki。

I had this issue because I had a conflicting install of Anaconda in the system that I was in the middle of removing.我遇到这个问题是因为我正在删除的系统中安装了 Anaconda 有冲突。 Once I cleaned up all vestiges of anaconda from my shell, it started working!一旦我从我的 shell 中清除了 anaconda 的所有痕迹,它就开始工作了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM