从 Python 获取 *.exe 的愿望导致了此处和此处描述的问题。
我理解不可能回答这类问题,我将描述我对如何从 Python 代码中获取 exe 文件的理解。你能指出概念上的缺陷吗?所以:
我们将代码带入工作状态。我们至少检查菜单所有分支上代码的可运行性。
检查所有导入的模块(安装了 conda 和安装了 pip)
指定要手动包含在复制文件中的 tkinter dll 的路径。在这里我不知道 - 如何处理我的 mysql 连接?
我们将所有内容都转移到脚本中并等待它被创建。
我开始 - 一个黑色的窗口闪烁了一秒钟,一切都无声无息地关闭了。
好吧,这里是代码:'''Imports are automatically detected (normally) in the script to freeze ))) ''' cx_Freeze.setup( name="Name_1st_exe", description='My Hello World App!', options={ "build_exe": { "packages": [ "tkinter", "matplotlib", "functools", "json", "time", "datetime", "pathlib", "PIL", "winsound", "mysql", "PyPDF2", "fitz", 'numpy', 'collections', 'requests', 'pprint', 'abc', ], "include_files": [ r"D:\OD\OneDrive\PyCodes\AnaPy\ICO\python-powered-h-140x182.ico", r"D:\Games\Anaconda\envs\postman\Library\bin\tcl86t.dll", r"D:\Games\Anaconda\envs\postman\Library\bin\tk86t.dll", # может, что то еще? ], 'include_msvcr': True, } }, version="0.2", executables=executables)
我可以补充一点,该程序集是在 Windows 10 上完成的,以便在 Windows 10 上运行。Python = 3.9.7 全部来自 Anaconda。
我不得不使用conda install some_modules -c conda-forge.
无法看到所需的 tkinter 菜单)
也许是希望MySQL在程序集中使用的问题,或者是抽象类的模块abc。如果有人分享他们创建此类程序集的经验,我将不胜感激。
添加。 回应 - 有人从 Tkinter + abc + mysql 得到一个 exe 吗?或者我是唯一一个试图这样做的人......
通过 pyinstaller 转换时我遇到了类似的问题。该脚本在运行时引用了其他可执行文件。我是这样解决的:
在脚本本身中,写入可执行文件的相对路径,例如 -
parent_dir = path.dirname(path.abspath(__file__))使用 --onefile 属性从命令行运行 pyinstaller
pyinstaller --onefile my_script.py在 my_script.spec 文件(第一次运行 pyinstaller 时自动生成)中,您需要指定:
使用配置文件从命令行运行 pyinstaller
pyinstaller myscript.spec my_script.py根据这个答案决定https://stackoverflow.com/questions/39563851/how-to-include-chromedriver-with-pyinstaller