美文网首页
关于fbs打包PyQt5应用程序

关于fbs打包PyQt5应用程序

作者: ab02f58fd803 | 来源:发表于2021-01-12 11:16 被阅读0次

前言

此内容是关于使用PyQt5打包使用sklearnmatplotlibpandas等过程出现的问题以及解决策略。

软件版本

Python 3.6.6   [MSC v.1900 64 bit (AMD64)] on win32

matplotlib                3.0.3
numpy                     1.19.5
pandas                    1.1.5
scikit-learn              0.24.0
seaborn                   0.11.1
scipy                     1.4.1

fbs                       0.9.0
PyQt5                     5.9.2
PyInstaller               3.4  development

这里需要说明的是由于fbs 0.9.0使用的是PyInstaller 3.4版本,因此需要使用PyInstaller 3.4 develop手动改写一些代码,如何自己手动改写第三方库并且使用,请参见python 第三方库中添加需求代码,使用这个develop添加代码主要有两个作用,一个是修改原始库中一个小bug,另一个是需要在fbs freeze --debug报错中不断添加内容,后面会进行说明。

fbs使用

  1. 建立虚拟环境
    : )虚拟环境非常重要,不会干预整体python环境的库,同时在虚拟环境中你可以根据需求随时更换库的版本
# 在想建立的文件目录下
#
python/python3 -m venv myfbsvenv

call myfbsvenv\scripts\activate.bat

fbs startproject

fbs run

fbs freeze

fbs installer

  1. 激活虚拟环境


    激活虚拟环境.png
  2. 创建 src,并演示程序,在虚拟环境下
    demo.png
  3. 不在虚拟环境下,程序可以运行,这个说明此时类库使用的计算机环境中的。
    demo.png

上面两个环境一定要非常清楚!!!

打包过程的问题

因为我这里是已经在虚拟环境下打包成功,因此这个在计算机环境中演示错误。

  1. 一般情况下使用
fbs run

可以成功运行的,但是在

fbs freeze

打包后不能成功运行时,我们需要使用

fbs freeze --debug

输出打包过程,这个过程一定注意warning这样的问题,这些问题往往使程序不能运行起来。

  1. lib not found:
    warning not find.png

找到对应文件路径

E:\Python\Python36\lib\site-packages\zmq

我这里是虚拟路径展示

F:\notebook\AGBGUI20210109\venv\venv\Lib\site-packages\zmq

把下面的内容复制到对应的文件目录下即可

image.png

:)遇到以上的问题不论是哪个库都可以这样解决, 并且,一定记住只要在虚拟环境中,你就可以将libzmq.cp36-win_amd64.pyd复制到任何一个带[xxxxx].cp36-win_amd64.pyd

  1. WARNING: Hidden import "sklearn.utils.lgamma" not found!
    image.png
    这种需要我们到Pyinstaller 3.4 文件路径下 添加内容。
F:\*****\venv\venv\development\PyInstaller-3.4\PyInstaller\hooks
sklearn.png

hook-sklearn.py 中加入
from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('sklearn')

from PyInstaller.utils.hooks import collect_data_files
# Tested on Windows 7 64bit with scikit-learn 0.17 and Python 2.7
hiddenimports = ['sklearn.utils.sparsetools._graph_validation',
                 'sklearn.utils.sparsetools._graph_tools',
                 'sklearn.utils.lgamma',
                 'sklearn.utils.weight_vector',
                 'sklearn.utils._weight_vector',
                 'sklearn.utils._cython_blas',
                 'sklearn.neighbors._typedefs',
                 'sklearn.neighbors._quad_tree',
                 'sklearn.neighbors.quad_tree',
                 'sklearn.tree',
                 'sklearn._tree',
                 'sklearn.tree._utils',
                 'sklearn._tree._utils']

datas = collect_data_files('sklearn')

:) 因为我在做的过程中,不仅出现了sklearn的错误,还有hook-scipy.py and hook-pyearth.py的问题
hook-scipy.py

from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('scipy')


from PyInstaller.utils.hooks import collect_data_files
# Tested on Windows 7 64bit with scikit-learn 0.17 and Python 2.7
hiddenimports = [
                 'scipy.special.cython_special',
                 'scipy._lib.messagestream',
                 ]

datas = collect_data_files('scipy')

hook-pyearth.py

from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('pyearth')


from PyInstaller.utils.hooks import collect_data_files
# Tested on Windows 7 64bit with scikit-learn 0.17 and Python 2.7
hiddenimports = [
                 'pyearth._basis',
                 'pyearth._record',
                 'pyearth._qr',
                 'pyearth._knot_search',
                 ]

datas = collect_data_files('pyearth')

:)同样的道理,如果其他库出现这种类似的问题,与上面的过程一致即可,但是,pyinstaller develop必须重新生成。

最后

:):)我把我修改成功的虚拟环境上传到百度云盘(文件过大只上传了Pyinstaller 3.4 develop),如有需要直接下载使用,我会写一个使用教程

如果有什么问题,可以交流讨论,邮箱ali_ma@yeah.net

链接: https://pan.baidu.com/s/1qIQNA99cZrFWnzqhmqZ6iA 提取码: upea

相关文章

网友评论

      本文标题:关于fbs打包PyQt5应用程序

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