3

我在 VS2012 中使用 python 导入时遇到问题。使用导入时,我无法编译/运行项目。如果我没有任何导入,python 将运行 main ok(并打印“hello world”)。这似乎是 VS 的错误,可能是配置,因为当我在 VS 中禁用异常时,它运行良好。

起初它错误地说:

[WinError 2] The system cannot find the file specified

如果我继续几次,它会显示:

[WinError 2] The system cannot find the file specified: 'C:\\Users\\Drew Cross\\Documents\\Visual Studio 2012\\Projects\\Test\\Model\\__init__.pyd'

然后它终于在继续运行了几次。

我有以下目录结构:

main.py
Model
    /__init__.py
    /graph.py

主要.py:

import Model.graph

def main():
    print('Hello World')

if __name__ == '__main__':main()

图.py:

class graph():
    def __init__(self):
        neighbors = []
4

1 回答 1

2

FileNotFoundError我在使用 Python 3.3 时看到了这一点,它引发了 Python Tools for Visual Studio 尚未正确抑制的新异常(例如)。

临时解决方法是忽略以下异常,这些异常通常在导入过程中引发。您可以通过添加以下 Python 异常(通过 Visual Studio 的异常对话框)并取消选中“用户未处理”以忽略它们来做到这一点。

  • exceptions.FileNotFoundError
  • exceptions.PermissionError
  • zipimport.ZipImportError

更多讨论可以在这个讨论中找到。

于 2012-10-11T19:29:20.777 回答