简体   繁体   English

为什么我的 pyinstaller 不提取任何 exe 文件

[英]Why doesn't my pyinstaller extract any exe files

I created a project for my friend and I would like to ask how can I solve my problem with PyInstaller?我为我的朋友创建了一个项目,我想问如何解决我的 PyInstaller 问题?

My problem is that when I type我的问题是当我输入

pyinstaller myprogram.py pyinstaller myprogram.py

It does create folders, but I can't find the .exe anywhere in them.它确实创建了文件夹,但我在其中的任何地方都找不到.exe It should be in dist, but it isn't.它应该在 dist 中,但不是。

Problem问题

The problem is that pyinstaller automatically bundles everything into your myprogram folder under dist .问题是pyinstaller自动将所有内容捆绑到您的myprogram文件夹下dist In that folder, you will find a myprogram.exe file that you can run.在该文件夹中,您将找到一个可以运行的myprogram.exe文件。 However, this isn't that convenient.但是,这不是那么方便。

Solution解决方案

Adding the option, --onefile , such that pyinstaller --onefile myprogram.py should bundle all files into one exe under the dist folder.添加选项--onefile ,这样pyinstaller --onefile myprogram.py应该将所有文件捆绑到dist文件夹下的一个exe中。

-F will also work; -F也可以; however, it's less readable if you're going to come back to it later.但是,如果您稍后要返回它,它的可读性会降低。

Footnotes脚注

This will create a console when you run the .exe file - if you have a GUI in your script (like Tkinter or PyQt), use --windowed .这将在您运行.exe文件时创建一个控制台 - 如果您的脚本中有 GUI(如 Tkinter 或 PyQt),请使用--windowed

Alternatively, you could do --onedir and send your friend an entire folder - may be a little easier.或者,您可以执行--onedir并将整个文件夹发送给您的朋友 - 可能会更容易一些。

Adding the --add-data {filename}:DATA will bundle files with your exe - use sys._MEIPASS (see this great StackOverflow post ).添加--add-data {filename}:DATA会将文件与您的 exe 捆绑在一起 - 使用sys._MEIPASS (请参阅这篇很棒的 StackOverflow 帖子)。

And finally, if you're just printing stuff, the console window will close as soon as everything's done.最后,如果您只是打印内容,控制台 window 将在一切完成后立即关闭。

See here for other options commonly used.有关常用的其他选项,请参见此处

Solutions解决方案

This may seem obvious but- delete the files created by pyinstaller and run pyinstaller again.这似乎很明显,但删除 pyinstaller 创建的文件并再次运行 pyinstaller。

If that doesn't work try and reinstall pyinstaller.如果这不起作用,请尝试重新安装 pyinstaller。

In worse case scenario, Use another software to make.exe files from.py files.在更糟糕的情况下,使用其他软件从 .py 文件中生成 .exe 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM