matplotlib和cx_freeze问题 [英] Issue with matplotlib and cx_freeze
问题描述
我正在尝试冻结基于控制台的程序,该程序使用matplotlib.pyplot生成并保存绘图。 (在保存之前,无论如何我都不需要预览或查看图。)这是我的setup.py脚本:
I'm trying to freeze a console-based program that uses matplotlib.pyplot to generate and save plots. (I don't need to preview or view the plots in anyway before they are saved.) Here's my setup.py script:
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')]
)
我可以编译程序,但是当我运行制图模块时,它返回以下错误:
I can compile the program, but when I run the graphing module it returns the following error:
此应用程序无法启动,因为无法找到或加载Qt平台插件中的 windows
。
重新安装该应用程序可能会解决此问题
据我所知,因为matplotlib希望加载/使用Qt GUI,但是因为它是一个控制台应用程序,所以cx_freeze不会载入Qt吗?这是对问题的正确解释吗?对如何解决此问题有任何想法吗?
From what I can tell, because matplotlib wants to load/use the Qt GUI, but because it's a console application cx_freeze doesn't load Qt? Is this a correct interpretation of the problem? Any thoughts on how to solve this problem?
推荐答案
您需要将Qt平台插件添加到分发目录中。尝试一下,将PyQt安装的库Li插件\平台
复制到您的 package / dist
目录。如果这对您有用,则可以在 include_files
构建选项中添加目录。我正在使用miniconda,因此platform目录位于 c:\miniconda\Library\plugins
。
You need to add the Qt platform plugins to your distribution directory. Give it a try and copy Library\plugins\platforms
of the PyQt installation to your package/dist
directory. If this works for you you can add the directory in your include_files
build option. I'm using miniconda so the platforms directory is in 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')]
)
这篇关于matplotlib和cx_freeze问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!