2012-10-01 52 views
3

我在使用VS2012中的python導入時遇到問題。在使用導入時,我無法讓項目編譯/運行。如果我沒有任何導入,python將運行主ok(並打印「hello world」)。這似乎是VS的錯誤,也許是一個配置,因爲當我禁用VS中的異常,它運行良好。Python導入在VS2012中不起作用

起初它錯誤說:

[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 = [] 

回答

2

我使用Python 3.3的時候看到了這一點,這引發了Python工具for Visual Studio尚未糾正的新異常(例如FileNotFoundError) y壓制。

臨時解決方法是忽略以下異常,這些異常通常在導入過程中引發。您可以通過添加以下Python異常(通過Visual Studio的異常對話框)並取消選中「用戶未處理」來忽略它們。

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

更多的討論在this discussion找到。