美文网首页
pyinstaller踩坑记

pyinstaller踩坑记

作者: 唯此 | 来源:发表于2018-11-29 08:02 被阅读0次

基本命令

pip install pyinstaller
cmd里面进入jobs2.py所在的文件夹。
pyinstaller -w -F --add-data "templates;templates" --add-data "static;static" jobs2.py
上面的-w选项是去掉运行时的cmd窗口,--add-data选项是打包非python代码文件进去, -F代表编译为单个exe文件。

坑: PyQt5报错

Exception:

        Cannot find existing PyQt5 plugin directories

        Paths checked: C:/Miniconda3/conda-bld/qt_1535195524645/_h_env/Library/plugins

方案: pip install PyQt5
网上说法:
Unfortunately, conda's version of PyQt5 is broken -- it returns invalid paths when querying QLibraryInfo. The pip-installed version would work fine.
@roynielsen17, you're correct that Python 2.7 is supported until 2020; Pyinstaller will support Python 2.7 until that date as well. However, PyQt5 doesn't support Python 2.7 -- that's the core roadblock.

|

坑: 安装的时候出现permission error

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: 'd:\programdata\anaconda3\Lib\site-packages\PyQt5\Qt\bin\d3dcompiler_47.dll'
Consider using the --user option or check the permissions.
方案: 使用虚拟环境来安装
D:\GoogleDrive\2_2017Dev\Py\yescript\runcodedesign>activate base
(base) D:\GoogleDrive\2_2017Dev\Py\yescript\runcodedesign>pip install PyQt5

网上大神的说法:
You are trying to install the package to a system folder which you don't have permissions to write to.
You have three options(use only one of them):
1-setup a virtual env to install the package (recommended):
python3 -m venv env
source ./env/bin/activate
python -m pip install google-assistant-sdk[samples]
2-Install the package to the user folder:
python -m pip install --user google-assistant-sdk[samples]
3-use sudo to install to the system folder (not recommended)
sudo python -m pip install google-assistant-sdk[samples]

坑: 运行jobs.exe 报TemplateNotFound错误

这一类问题都是找不到所需要的文件。一般都需要把文件附带上去,同时重新设计相对路径。参考说明
pyinstaller -w -F --add-data "templates;templates" --add-data "static;static" jobs.py
方案:需要把下面的逻辑加上去。sys._MEIPASS是exe在运行时候的目录。

if getattr(sys, 'frozen', False):
  template_folder = os.path.join(sys._MEIPASS, 'templates') #sys._MEIPASS is a temporary folder for PyInstaller
  app = Flask(__name__, template_folder=template_folder)
else:
  app = Flask(__name__)

坑: mutiprocess打包之后不停执行,导致内存溢出

解决方案:

if __name__ == '__main__':
    multiprocessing.freeze_support()
    # my code

网上大神:
The reason is lack of fork() on Windows (which is not entirely true). Because of this, on Windows the fork is simulated by creating a new process in which code, which on Linux is being run in child process, is being run. As the code is to be run in technically unrelated process, it has to be delivered there before it can be run. The way it's being delivered is first it's being pickled and then sent through the pipe from the original process to the new one. In addition this new process is being informed it has to run the code passed by pipe, by passing --multiprocessing-fork command line argument to it. If you take a look at implementation of freeze_support() function its task is to check if the process it's being run in is supposed to run code passed by pipe or not.

坑: 引入six的时候会报错

升级setuptools
pip install --upgrade setuptools

image.png

相关文章

  • pyinstaller踩坑记

    基本命令 pip install pyinstallercmd里面进入jobs2.py所在的文件夹。pyinsta...

  • pyinstaller 踩坑

    报错 参见 https://www.tutorialexample.com/fix-pyinstaller-upx...

  • Android Material Design 踩坑记(2)

    Android Material Design 踩坑记(1) CoordinatorLayout Behav...

  • Deepin使用踩坑记

    1. 前言 很喜欢Deepin,奈何坑太多,不过不怕,踩过去~ 2. 踩坑记 2.1 Deepin重启后文件管理器...

  • SpringStreaming+Kafka

    摘自 :Spark踩坑记——Spark Streaming+Kafka [TOC] SpringStreaming...

  • 原生App植入React Native 踩坑记

    原生App植入React Native 踩坑记 为什么我踩坑了有一个需求要去可以在当前工程的feature/RN ...

  • [ANR Warning]onMeasure time too

    ConstraintLayout 踩坑记一次封装组合控件时的坑,我才用了集成 ConstraintLayout 来...

  • IdentityServer 部署踩坑记

    IdentityServer 部署踩坑记 Intro 周末终于部署了 IdentityServer 以及 Iden...

  • 踩坑记

    1、android自签名证书Glide加载不出图片 关于https中自签名证书的介绍以及OkHttp中解决自签名证...

  • 踩坑记

    6月初,看到广西龙脊梯田有个疏秧节,很是心动!我十几年前就去过龙脊,当时觉得整片的梯田又美又壮观,壮族风情浓厚,就...

网友评论

      本文标题:pyinstaller踩坑记

      本文链接:https://www.haomeiwen.com/subject/zgfxcqtx.html