尝试在customtkinter上使用pyinstaller

问题描述 投票:0回答:2

我尝试根据官方文档在customtkinter上使用pyinstaller,但是没有成功。

我的命令(我使用Mac OS): pyinstaller --noconfirm --onedir --windowed --add-data "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/customtkinter ;customtkinter/" “TROLL.py”

我的错误信息:

usage: pyinstaller [-h] [-v] [-D] [-F] [--specpath DIR] [-n NAME] [--add-data <SRC;DEST or SRC:DEST>] [--add-binary <SRC;DEST or SRC:DEST>] [-p DIR] [--hidden-import MODULENAME]
                   [--collect-submodules MODULENAME] [--collect-data MODULENAME] [--collect-binaries MODULENAME] [--collect-all MODULENAME] [--copy-metadata PACKAGENAME]
                   [--recursive-copy-metadata PACKAGENAME] [--additional-hooks-dir HOOKSPATH] [--runtime-hook RUNTIME_HOOKS] [--exclude-module EXCLUDES] [--key KEY] [--splash IMAGE_FILE]
                   [-d {all,imports,bootloader,noarchive}] [--python-option PYTHON_OPTION] [-s] [--noupx] [--upx-exclude FILE] [-c] [-w] [-i <FILE.ico or FILE.exe,ID or FILE.icns or Image or "NONE">]
                   [--disable-windowed-traceback] [--version-file FILE] [-m <FILE or XML>] [--no-embed-manifest] [-r RESOURCE] [--uac-admin] [--uac-uiaccess] [--win-private-assemblies]
                   [--win-no-prefer-redirects] [--argv-emulation] [--osx-bundle-identifier BUNDLE_IDENTIFIER] [--target-architecture ARCH] [--codesign-identity IDENTITY] [--osx-entitlements-file FILENAME]
                   [--runtime-tmpdir PATH] [--bootloader-ignore-signals] [--distpath DIR] [--workpath WORKPATH] [-y] [--upx-dir UPX_DIR] [-a] [--clean] [--log-level LEVEL]
                   scriptname [scriptname ...]
pyinstaller: error: argument --add-data: invalid add_data_or_binary value: '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/customtkinter;customtkinter/'

为什么要这么做?

我查看了文档,却找不到我的问题。

python pyinstaller customtkinter
2个回答
0
投票

您可能想要使用 auto-py-to-exe 而不是 pyinstaller 。使用起来更方便。

要安装它,请运行:

pip install auto-py-to-exe
要启动它,请在命令提示符中输入:
auto-py-to-exe

希望它对你有用。


0
投票

我设法通过将添加数据标志的分号更改为冒号来使其工作。

pyinstaller --noconfirm --onedir --windowed --add-data "<CustomTkinter Location>/customtkinter:customtkinter/"  "main.py"

或者,您可以在 .spec 文件中手动添加数据位置。

生成规格文件

pyi-makespec --onedir --windowed "main.py"

这将生成一个您可以编辑的 .spec 文件。在“分析”->“数据”部分下包含 customtkinter 库的路径。

a = Analysis(
    ['main.py'],
    pathex=[],
    binaries=[],
    datas=[('/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/customtkinter', 'customtkinter/')],
    hiddenimports=[],
    hookspath=[],
    hooksconfig={},
    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(...)
coll = COLLECT(...)
app = BUNDLE(...)

之后跑步

pyinstaller main.spec

希望它对你有用。

© www.soinside.com 2019 - 2024. All rights reserved.