使用 --onefile for pyinstaller 不会创建单个可执行文件,而是不断创建一个目录



我有一个python脚本和一个python规范文件。spec 文件包含一些代码,这些代码添加了我的脚本所需的几个目录。当我这样做时

pyinstaller script.spec script.py

它像往常一样创建一个目录。但是当我这样做时

pyinstaller --onefile script.spec script.py

它确实创建了一个可执行文件,相反,它执行与我没有包含它相同的操作。

是与我的命令行有关还是与规范文件有关?

规范文件代码:

# -*- mode: python ; coding: utf-8 -*-
block_cipher = None

a = Analysis(['memrise.py'],
pathex=['C:\Users\blahblahpath\memrise'],
binaries=[],
datas=[('C:\Users\blahblahpath\memrise\chromedriver_win32\','.\selenium\webdriver\')],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='memrise',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
Tree('C:\Users\blahblahpath\memrise\assets', prefix='assets\'),
Tree('C:\Users\blahblahpath\langdetect', prefix='langdetect\'),
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='memrise')

您的命令是正确的。

你需要做的是检查字典文件,

如果不使用 --onefile ,里面应该有很多文件

但是如果你使用,里面应该只有一个.exe文件。

最新更新