matplotlib和cx_freez问题

2024-03-29 09:35:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图冻结一个基于控制台的程序matplotlib.pyplot生成和保存绘图。(我不需要在保存之前预览或查看绘图。)以下是我的设置.py脚本:

from cx_Freeze import setup, Executable
import os

os.environ['TCL_LIBRARY'] = "C:\\Program Files\\Anaconda3\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Program Files\\Anaconda3\\tcl\\tk8.6"

setup(name='FLOUResence.exe',
    version='0.1',
    options = {"build_exe": {"packages":["pandas", "numpy", "scipy", "matplotlib"]}
           },
executables = [Executable(script='caller.py', targetName='FLOUResence.exe', 
icon="icon.ico", base='Console')]
)

我可以编译程序,但当我运行绘图模块时,它返回以下错误:

This application failed to start because it could not find or load the Qt platform plugin "windows" in "".
Reinstalling the application may fix this problem.

据我所知,因为matplotlib希望加载/使用qtgui,但因为它是一个控制台应用程序,cx斨u freeze不能加载Qt?这是对问题的正确解释吗?对如何解决这个问题有什么想法吗?在


Tags: pyimport绘图matplotlibossetuplibraryenviron
1条回答
网友
1楼 · 发布于 2024-03-29 09:35:55

您需要将Qt平台插件添加到您的分发目录中。尝试一下,将PyQt安装的Library\plugins\platforms复制到package/dist目录中。如果这对您有效,您可以在include_files构建选项中添加目录。我使用miniconda,所以platforms目录在c:\miniconda\Library\plugins。在

setup(name='FLOUResence.exe',
    version='0.1',
    options = {
        "build_exe": {"packages":["pandas", "numpy", "scipy", "matplotlib"],
                      "include_files": [r'c:\miniconda\Library\plugins\platforms']}
    },
    executables = [Executable(script='caller.py', targetName='FLOUResence.exe', 
                   icon="icon.ico", base='Console')]
)

相关问题 更多 >