pyinstaller .exe启动不正确
你好,我为我的学习学习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,没有任何反应。
有什么想法?
感谢
感谢
你怎么告诉pyinstaller编译.py
文件?
如果您使用pip安装了pyinstaller,请尝试运行这是与文件位于同一目录的命令提示符。
pyinstaller mypythonapp.py
的.exe
将在一个名为dist
新目录。要将exe作为一个文件在编译时使用命令提示符下的--onefile
参数。
我尝试过使用和不使用--onefile。 如果我直接用这些命令编译,我总是收到一条错误消息: site-package \ PyInstaller \ loader \ pyiboot01_bootstrap.py 25行, ModuleNotFindError:没有名为'os'的模块 – CDVC23
您是否尝试使用os而不导入它? – Dan
Nop im在我的代码中没有使用os,它是pyinstaller中的pyiboot01_boostrap.py文件,它尝试导入但失败: 文件“site-packages \ PyInstaller \ loader \ pyiboot01_bootstrap.py”,第25行,在
要引用代码中的文件,在使用pyinstaller时需要使用'sys._MEIPASS'作为基本路径 - 这是错误的常见来源。 – Dan
我试过用你的方法,我没有要添加的文件,所需的一切都在我的main.py中。 现在即时得到: site-package \ PyInstaller \ loader \ pyiboot01_bootstrap.py第25行,ModuleNotFindError:没有名为'os'的模块 – CDVC23
您是否导入os? – Dan