1

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 和本机代码中进行调试。这是失败后堆栈的样子:

混合使用调用堆栈

这是失败的 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__模块中没有字段:

模块对象的内容

loader 对象有很多字段,下面是其中的一些:

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

1 回答 1

0

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

重新安装 Quantlib 1.6.2 和 Quantlib SWIG 1.6.1

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

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

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

于 2015-11-24T11:05:13.317 回答