2017-10-18 156 views
1

你好,我爲我的學習學習python。 現在我試圖使用pyinstaller來獲取.exe文件,因爲它更容易分享。pyinstaller .exe啓動不正確

我的小程序使用Tkinter的,numpy的和matplotlib但是當我嘗試啓動它,什麼也沒有發生,它很奇怪,因爲我得到的編譯過程沒有錯誤:

pyinstaller main.spec 
531 INFO: PyInstaller: 3.4.dev0+133d18156 
531 INFO: Python: 3.6.2 
531 INFO: Platform: Windows-10-10.0.15063-SP0 
531 INFO: UPX is not available. 
531 INFO: Extending PYTHONPATH with paths 
['C:\\Users\\Charles\\eclipse-workspace\\algo2\\src', 
'C:\\Users\\Charles\\eclipse-workspace\\algo2\\src'] 
531 INFO: checking Analysis 
531 INFO: Building Analysis because out00-Analysis.toc is non existent 
531 INFO: Initializing module dependency graph... 
546 INFO: Initializing module graph hooks... 
578 INFO: Analyzing base_library.zip ... 
4672 INFO: Analyzing hidden import 'os' 
4719 INFO: Analyzing hidden import 'stat' 
4719 INFO: Analyzing hidden import 'ntpath' 
4781 INFO: Analyzing hidden import 'genericpath' 
4797 INFO: running Analysis out00-Analysis.toc 
4812 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable 
    required by c:\users\charles\anaconda3\python.exe 
5906 INFO: Caching module hooks... 
5922 INFO: Analyzing main.py 
5937 INFO: Loading module hooks... 
5937 INFO: Loading module hook "hook-encodings.py"... 
6078 INFO: Looking for ctypes DLLs 
6078 INFO: Analyzing run-time hooks ... 
6078 INFO: Looking for dynamic libraries 
6078 INFO: Looking for eggs 
6078 INFO: Using Python library c:\users\charles\anaconda3\python36.dll 
6078 INFO: Found binding redirects: 
[] 
6109 INFO: Graph cross-reference written to C:\Users\Charles\eclipse-workspace\algo2\src\build\main\xref-main.html 
6141 INFO: checking PYZ 
6141 INFO: Building PYZ because out00-PYZ.toc is non existent 
6141 INFO: Building PYZ (ZlibArchive) C:\Users\Charles\eclipse-workspace\algo2\src\build\main\out00-PYZ.pyz 
6344 INFO: Building PYZ (ZlibArchive) C:\Users\Charles\eclipse-workspace\algo2\src\build\main\out00-PYZ.pyz completed successfully. 
6344 INFO: checking PKG 
6344 INFO: Building PKG because out00-PKG.toc is non existent 
6344 INFO: Building PKG (CArchive) out00-PKG.pkg 
6406 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully. 
6422 INFO: Bootloader c:\users\charles\anaconda3\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run_d.exe 
6422 INFO: checking EXE 
6422 INFO: Building EXE because out00-EXE.toc is non existent 
6422 INFO: Building EXE from out00-EXE.toc 
6422 INFO: Appending archive to EXE C:\Users\Charles\eclipse-workspace\algo2\src\build\main\main.exe 
6516 INFO: Building EXE from out00-EXE.toc completed successfully. 
6531 INFO: checking COLLECT 
6531 INFO: Building COLLECT because out00-COLLECT.toc is non existent 
6547 INFO: Building COLLECT out00-COLLECT.toc 
7359 INFO: Building COLLECT out00-COLLECT.toc completed successfully. 

所以我試圖用編譯調試,我沒有看到什麼不對:

main.exe>log.txt 
[3912] PyInstaller Bootloader 3.x 
[3912] LOADER: executable is C:\Users\Charles\eclipse-workspace\algo2\src\dist\main\main.exe 
[3912] LOADER: homepath is C:\Users\Charles\eclipse-workspace\algo2\src\dist\main 
[3912] LOADER: _MEIPASS2 is NULL 
[3912] LOADER: archivename is C:\Users\Charles\eclipse-workspace\algo2\src\dist\main\main.exe 
[3912] LOADER: No need to extract files to run; setting extractionpath to homepath 
[3912] LOADER: SetDllDirectory(C:\Users\Charles\eclipse-workspace\algo2\src\dist\main) 
[3912] LOADER: Already in the child - running user's code. 
[3912] LOADER: Python library: C:\Users\Charles\eclipse-workspace\algo2\src\dist\main\python36.dll 
[3912] LOADER: Loaded functions from Python library. 
[3912] LOADER: Manipulating environment (sys.path, sys.prefix) 
[3912] LOADER: Pre-init sys.path is C:\Users\Charles\eclipse-workspace\algo2\src\dist\main\base_library.zip;C:\Users\Charles\eclipse-workspace\algo2\src\dist\main 
[3912] LOADER: sys.prefix is C:\Users\Charles\eclipse-workspace\algo2\src\dist\main 
[3912] LOADER: Setting runtime options 
[3912] LOADER: Initializing python 
[3912] LOADER: Overriding Python's sys.path 
[3912] LOADER: Post-init sys.path is C:\Users\Charles\eclipse-workspace\algo2\src\dist\main\base_library.zip;C:\Users\Charles\eclipse-workspace\algo2\src\dist\main 
[3912] LOADER: Setting sys.argv 
[3912] LOADER: setting sys._MEIPASS 
[3912] LOADER: importing modules from CArchive 
[3912] LOADER: extracted struct 
[3912] LOADER: callfunction returned... 
[3912] LOADER: extracted pyimod01_os_path 
[3912] LOADER: callfunction returned... 
[3912] LOADER: extracted pyimod02_archive 
[3912] LOADER: callfunction returned... 
[3912] LOADER: extracted pyimod03_importers 
[3912] LOADER: callfunction returned... 
[3912] LOADER: Installing PYZ archive with Python modules. 
[3912] LOADER: PYZ archive: out00-PYZ.pyz 
[3912] LOADER: Running pyiboot01_bootstrap.py 
[3912] LOADER: OK. 
[3912] LOADER: Cleaning up Python interpreter. 

這裏我的.spec文件:

# -*- mode: python -*- 
import sys 

block_cipher = None 


a = Analysis(['main.py'], 
      pathex=['C:\\Users\\Charles\\eclipse-workspace\\algo2\\src'], 
      binaries=[], 
      datas=[], 
      hiddenimports=['os', 'stat', 'ntpath', 'genericpath'], 
      hookspath=[], 
      runtime_hooks=[], 
      excludes=[], 
      win_no_prefer_redirects=False, 
      win_private_assemblies=False, 
      cipher=block_cipher 
      ) 
pyz = PYZ(a.pure, a.zipped_data, 
      cipher=block_cipher 
      ) 
exe = EXE(pyz, 
      a.binaries + [('msvcp100.dll', 'C:\\Windows\\System32\\msvcp100.dll', 'BINARY'), 
         ('msvcr100.dll', 'C:\\Windows\\System32\\msvcr100.dll', 'BINARY')] 
      if sys.platform == 'win32' else a.binaries, 
      exclude_binaries=True, 
      name='main', 
      debug=False, 
      strip=False, 
      upx=False, 
      console=False) 
coll = COLLECT(exe, 
       a.binaries, 
       a.zipfiles, 
       a.datas, 
       strip=False, 
       upx=False, 
       name='main') 

如果我使用python解釋器運行它,我的程序沒有問題。 試圖啓動帶有和沒有控制檯的.exe,沒有任何反應。

有什麼想法?

感謝

感謝

+0

要引用代碼中的文件,在使用pyinstaller時需要使用'sys._MEIPASS'作爲基本路徑 - 這是錯誤的常見來源。 – Dan

+0

我試過用你的方法,我沒有要添加的文件,所需的一切都在我的main.py中。 現在即時得到: site-package \ PyInstaller \ loader \ pyiboot01_bootstrap.py第25行,ModuleNotFindError:沒有名爲'os'的模塊 – CDVC23

+0

您是否導入os? – Dan

回答

0

你怎麼告訴pyinstaller編譯.py文件?

如果您使用pip安裝了pyinstaller,請嘗試運行這是與文件位於同一目錄的命令提示符。

pyinstaller mypythonapp.py

.exe將在一個名爲dist新目錄。要將exe作爲一個文件在編譯時使用命令提示符下的--onefile參數。

+1

我嘗試過使用和不使用--onefile。 如果我直接用這些命令編譯,我總是收到一條錯誤消息: site-package \ PyInstaller \ loader \ pyiboot01_bootstrap.py 25行, ModuleNotFindError:沒有名爲'os'的模塊 – CDVC23

+0

您是否嘗試使用os而不導入它? – Dan

+1

Nop im在我的代碼中沒有使用os,它是pyinstaller中的pyiboot01_boostrap.py文件,它嘗試導入但失敗: 文件「site-packages \ PyInstaller \ loader \ pyiboot01_bootstrap.py」,第25行,在 ModuleNotFoundError:No名爲'os'的模塊 – CDVC23