我到处查找,但对一个相当琐碎的问题没有得到明确的答复。
我在 Windows 7 上的 PyCharm 中有一个 Python 项目,其中包含多个.py文件(通过“”连接from %package_name%.%script_name% import %class_name%)和项目内的一个文件夹,其中包含两个简单的文本文件。我已将 PyInstaller 3.6 安装到项目中venv并将其用作指向.spec文件的外部工具。到目前为止,一切都很好。文件.spec内容如下:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['C:\\Users\\%username%\\PycharmProjects\\%project_folder%\\%project_folder%\\main.py'],
pathex=['C:\\Users\\%username%\\PycharmProjects\\%project_folder%\\%project_folder%'],
binaries=[],
datas=[('txt_files\\file1.txt', '.'), ('txt_files\\file2.txt', '.')],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
a.datas += [
("C:\\Users\\%username%\\PycharmProjects\\%project_folder%\\%project_folder%\\txt_files\\file1.txt","txt_files\\file1.txt","DATA"),
("C:\\Users\\%username%\\PycharmProjects\\%project_folder%\\%project_folder%\\txt_files\\file2.txt","txt_files\\file2.txt","DATA"),
]
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='%project_name%',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe, …Run Code Online (Sandbox Code Playgroud)