【问题标题】:Visual Studio 2015 Python 3.5 debug startup errorVisual Studio 2015 Python 3.5 调试启动错误
【发布时间】:2015-11-23 11:21:05
【问题描述】:

Python 3.5 调试启动错误

我尝试使用 Visual Studio 2005 在调试模式下启动一个小型 Python 程序。但它无法到达第一条语句,即 import 语句。为什么会出现如下所述的__file__ 错误?

一个名为 Swap.py 的 Quantlib 示例在 Visual Studio 2015 中以发布模式运行而没有错误。但在调试模式下,它在启动时会出现此错误:

Additional information: 'module' object has no attribute '__file__'

Quantlib 版本是 1.6.2,QuantLib SWIG 版本是 1.6.1。

这是 swap.py 的第一行,但并没有那么远:

from QuantLib import *

我安装了 Python 3.5 调试组件。

然后在 Visual Studio 2015 for Python 中,我创建了一个 Python 环境来使用 python_d.exe、pythonw_d.exe 和 python35_d.dll。

输出窗口:

'python_d.exe' (Win32): Loaded 'C:\Program Files (x86)\Python 3.5\python_d.exe'. Symbols loaded.
'python_d.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'python_d.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'python_d.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'python_d.exe' (Win32): Loaded 'C:\Program Files (x86)\Python 3.5\python35_d.dll'. Symbols loaded.
'python_d.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. Cannot find or open the PDB file.
'python_d.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Cannot find or open the PDB file.
'python_d.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ws2_32.dll'. Cannot find or open the PDB file.    <frozen importlib._bootstrap>!_spec_from_module Line 483 Python
<frozen importlib._bootstrap>!_setup Line 1107           Python
<frozen importlib._bootstrap>!_install Line 1134     Python
[External Code]
python_d.exe!wmain(int argc, wchar_t * * argv) Line 14     C
[External Code]
'python_d.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
'python_d.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nsi.dll'. Cannot find or open the PDB file.
'python_d.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'python_d.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'python_d.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
'python_d.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'python_d.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
'python_d.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Cannot find or open the PDB file.
'python_d.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptsp.dll'. Cannot find or open the PDB file.
'python_d.exe' (Win32): Loaded 'D:\ProgramFiles\vc2015\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.2\Microsoft.PythonTools.Debugger.Helper.x86.dll'. Symbols loaded.
'python_d.exe' (Python): Loaded ''. Module was built without symbols.
The thread 0x26d4 has exited with code 1577189376 (0x5e020000).
'python_d.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rsaenh.dll'. Cannot find or open the PDB file.
'python_d.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcrypt.dll'. Cannot find or open the PDB file.
'python_d.exe' (Python): Loaded '<frozen importlib._bootstrap>'. Module was built without symbols.
AttributeError
Additional information: 'module' object has no attribute '__file__'

堆栈:

<frozen importlib._bootstrap>!_spec_from_module Line 483    Python
<frozen importlib._bootstrap>!_setup Line 1107              Python
<frozen importlib._bootstrap>!_install Line 1134            Python
[External Code]
python_d.exe!wmain(int argc, wchar_t * * argv) Line 14        C
[External Code]

我能够调试 Python 代码(至少可以查看 Visual Studio Locals)。我们需要能够在 Python 和本机代码中进行调试。这是失败后堆栈的样子:

Mixed Use Call Stack

这是失败的 Python 函数(代码为失败点):

def _spec_from_module(module, loader=None, origin=None):
    # This function is meant for use in _setup().
    try:
        spec = module.__spec__
    except AttributeError:
        pass
    else:
        if spec is not None:
            return spec
    name = module.__name__
    if loader is None:
        try:
            loader = module.__loader__
        except AttributeError:
            # loader will stay None.
            pass
    try:
        location = module.__file__

但是模块中没有__file__字段:

Contents of module object

加载器对象有很多字段,但这里有一些:

loader    has type class BuiltinImporter
loader.__module__'_frozen_importlib'                str
loader.__mro__     (<class 'BuiltinImporter'>, <class 'object'>)    tuple

【问题讨论】:

标签: python-3.x visual-studio-2015 visual-studio-debugging quantlib-swig


【解决方案1】:

我得到了调试版本,如下所示:

重新安装 Quantlib 1.6.2 和 Quantlib SWIG 1.6.1

在调试模式下构建 Quantlib 和 Quantlib SWIG。

然后我仍然有一个启动错误,但更明显的是它正在查看不同版本的 Quantlib.py。

我删除了 VirtualStore 的内容: \Users\&lt;Username&gt;\AppData\Local\VirtualStore\Program Files (x86)\Python 3.5\Lib\site-packages\QuantLib\

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    • 2018-04-27
    • 1970-01-01
    相关资源
    最近更新 更多