需要帮助以pyinstaller编译python [英] need help to compile python with pyinstaller

查看:93
本文介绍了需要帮助以pyinstaller编译python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行Windows 7+的计算机上分发我的python代码.它由几个主要位于cprofiles_lmfit.py的.py文件以及一个描述GUI的文件cprofiles.ui和该文档的.pdf文件组成.

I want to distribute my python code on machines running windows 7+. It consists of a couple of .py files with the main in cprofiles_lmfit.py, together with a file cprofiles.ui to describe the GUI and a .pdf for the doc.

我很难过(请参阅

I had a hard time (see build a .exe for Windows from a python 3 script importing theano with pyinstaller for instance) but eventually made a suitable binary using pyinstaller with the command line:

pyinstaller --noupx --onefile --add-data="cprofiles.ui;." cprofiles_lmfit.py

除了上述链接中所述的theano模块有问题外,二进制文件还存在一些问题:

beside a problem with the theano module described in the above link, the binary still have a few problems:

  • .exe大小为220MB;我想减小尺寸.

  • the .exe is 220MB big; I would like reducing the size.

在运行.exe时,将打开一个控制台,并等待大约20秒钟,然后再打开GUI.打开GUI后,关闭控制台会终止GUI ...我想避免使用此控制台,而跳过〜20s.

when running the .exe a console opens and waits ~20 seconds before opening the GUI. Once the GUI is opened, closing the console kills the GUI... I would like avoiding this console and skip the ~20s.

ui文件必须与exe一起分发(在同一目录中);我曾希望'add-data'选项不会出现这种情况.我想包括它.

the ui file must be distributed together with the exe (in the same directory); I had hoped this shouldn't be the case with the 'add-data' option. I would like including it.

python环境的"Library/plugin"目录中的"platforms"目录也必须与exe一起分发.否则,在运行exe时会出现错误消息此应用程序无法启动,因为它无法找到qt平台插件窗口"(但是在构建时,pyinstaller并没有错误消息!).我想摆脱这个平台"游戏.

the ‘platforms’ directory from the ‘Library/plugin’ directory of the python environment must also be distributed along with the exe. Otherwise there is an error message when running the exe ‘this application has failed to start because it could not find the qt platform plugin windows’ (but there is no error message from pyinstaller when building !). I would like getting rid of this 'platforms' game.

您知道如何解决这些问题之一吗?

Do you know how to address one these points ?

2017年11月28日更新: 没有人 ?如果您能为上述几点做出贡献,请给我一个提示.

update nov 28, 2017: no one ? please if you can contribute to one of these points, give me a clue.

推荐答案

我认为我为您提供了更好的解决方案:将nsis与pyinstaller结合使用.

I think I have a better solution for you: Use nsis in conjunction with pyinstaller.

在这里更详细地回答:

  1. 文件很大,因为它包含完整的python环境.除了创建一个虚拟环境,该虚拟环境包含更少的文件并在代码中使用更少的程序包之外,我认为您没有什么能做的.
  2. 运行exe需要很长时间,因为您选择了--onefile选项.结果,它将解压缩exe,将其保存到临时目录,然后运行脚本.使用--onefile时,它实际上实际上不是可执行文件,而只是一个zip文件,该文件解压缩然后自行启动.更好的选择可能是:
  3. (和4.).与其使用--onefile选项,不如将其通常与pyinstaller打包在一起,然后在其上使用创建一个脚本. nsis .这样,用户可以运行安装程序,该安装程序将打包您放入nsis脚本中的所有文件(包括pyinstaller创建的所有文件)以及您想要的任何其他文件.将会有一个不错的设置界面,该界面还将创建.exe的快捷方式.
  1. The file is that big because it contains the full python environment. I don't think there's much you can do about it, except creating a virtual environment that contains less files and using less packages in your code.
  2. Running the exe takes a long time because you have chosen the --onefile option. As a result it will unzip the exe, save it to a temporarary directory, and then run the script. When using --onefile it's actually not really an executable, but just a zip file that unzips and then starts itself. A better option might be:
  3. (and 4.). Instead of using the --onefile option, just package it normally with pyinstaller, and then create a script on top of it with nsis. That way the user can run the installer, which will have packaged all the files you put in the nsis script (including all the files created by pyinstaller) and also any additional files you would like. There will be a nice setup interface that will also create a shortcut to the .exe.

这篇关于需要帮助以pyinstaller编译python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆