Python导入在VS2012中不起作用

时间:2012-10-01 05:49:25

标签: python-3.x visual-studio-2012

我在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

main.py:

import Model.graph

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

if __name__ == '__main__':main()

graph.py:

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

1 个答案:

答案 0 :(得分:2)

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

临时解决方法是忽略以下异常,这些异常通常在导入过程中引发。您可以通过添加以下Python异常(通过Visual Studio的Exceptions对话框)并取消选中“User-unhandled”来忽略它们。

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

可以在this discussion中找到更多讨论。