2017-06-09 36 views
2

我試圖將Python程序轉換爲可執行文件,使用py2exe,在tutorial flow之後。我創建了一個setup.py,如下所示(使用this示例)。使用py2exe轉換程序和傳遞選項時的RuntimeError

from distutils.core import setup 
    import py2exe 

    options = { 
     'py2exe': { 
      'compressed': 1, 
      'optimize': 2, 
      'bundle_files': 3, #Options 1 & 2 do not work on a 64bit system 
      'dist_dir': 'dist', # Put .exe in dist/ 
      'xref': False, 
      'skip_archive': False, 
      'ascii': False}} 

    setup(options=options, zipfile=None, console=['main.py']) 

當我在蟒蛇命令提示符(設置爲運行一個Python 3.5的環境)中運行python setup.py py2exe,我碰到下面的錯誤跟蹤:

running py2exe 
    Traceback (most recent call last): 
     File "setup.py", line 14, in <module> 
     }, zipfile=None, console=['main.py']) 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\distutils\core.py", line 148, in setup 
     dist.run_commands() 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\distutils\dist.py", line 955, in run_commands 
     self.run_command(cmd) 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\distutils\dist.py", line 974, in run_command 
     cmd_obj.run() 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run 
     self._run() 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run 
     builder.analyze() 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\runtime.py", line 173, in analyze 
     target.analyze(mf) 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\runtime.py", line 74, in analyze 
     modulefinder.run_script(self.script) 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 86, in run_script 
     self._scan_code(mod.__code__, mod) 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 394, in _scan_code 
     self.safe_import_hook(name, mod, fromlist, level) 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 138, in safe_import_hook 
     self.import_hook(name, caller, fromlist, level) 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 120, in import_hook 
     module = self._gcd_import(name) 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import 
     return self._find_and_load(name) 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 357, in _find_and_load 
     self._scan_code(module.__code__, module) 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 394, in _scan_code 
     self.safe_import_hook(name, mod, fromlist, level) 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 138, in safe_import_hook 
     self.import_hook(name, caller, fromlist, level) 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 120, in import_hook 
     module = self._gcd_import(name) 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import 
     return self._find_and_load(name) 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 356, in _find_and_load 
     if module.__code__: 
     File "C:\Users\<username>\AppData\Local\conda\conda\envs\py35_env\lib\site-packages\py2exe\mf3.py", line 637, in __code__ 
     raise RuntimeError("should read __file__ to get the source???") 
    RuntimeError: should read __file__ to get the source??? 

我嘗試以下回溯,但沒有能夠找出錯誤的根源。關於我的問題是什麼以及如何解決它的任何建議?

回答

0

看來我的錯誤與py2x的py2exe中缺少支持有關。當我運行在我的問題中鏈接的教程中列出的教程示例(hello world)時,我遇到了類似的錯誤(雖然不完全相同),這是我如何確定問題的。

我使用python 3.4解釋器創建了一個新的Anaconda環境,並且能夠成功地爲我的原始應用程序構建可執行文件。

相關問題