使用cxFreeze导入matplotlib.pyplot和BeautifulSoup

塞尔吉

我正在尝试使用cxFreeze为我的python脚本编译可执行文件。在我需要为脚本导入的许多库中,有两个似乎因cxFreeze而失败。特别是,请考虑以下test.py脚本:

print('matplotlib.pyplot')
import matplotlib.pyplot

使用cxFreeze编译并运行可得到以下输出:

matplotlib cxFreeze问题

分别使用以下test.py脚本:

print('BeautifulSoup from bs4')
from bs4 import BeautifulSoup

用cxFreeze编译后,产生以下输出: BeautifulSoup cxFreeze问题

我的cxFreeze的setup.py文件如下所示:

import sys
from cx_Freeze import setup, Executable

setup(
    name = "myname",
    version = "1.0",
    description = "some description",
    executables = [Executable("test.py", base = None)]    
)

我正在运行Python 3.3 x86,并且在Windows 7上使用32位版本的cxFreeze(最新)。

I am having trouble chasing down this issue. For one, the directory "C:\Python\32-bit..." doesn't exist on my computer, so I am unclear as to why cxFreeze is trying to look there. Does anyone have any idea how to approach this, or perhaps has already dealt with this issue?

Sergiy

After some digging around, I was able to resolve the issue. For those who may be encountering the same issue, this is what solved it for me:

For the issue with matplotlib: I simply needed to explicitly specify to cxFreeze to include matplotlib.backends.backend_tkagg. My setup file ended up looking like this:

import sys
from cx_Freeze import setup, Executable
packages = ['matplotlib.backends.backend_tkagg']

setup(
    name = "myname",
    version = "1.0",
    description = "some description",
    options = {'build_exe': {'packages':packages}},
    executables = [Executable("test.py", base = None)]    
)

至于BeautifulSoup问题:网络上有几篇有关此问题的文章:cx_freeze sre_constants.error不再重复https : //bitbucket.org/anthony_tuininga/cx_freeze/issue/59/sre_constantserror-nothing-重复相关结论:导致此问题的cxFreeze 4.3.2构建存在问题。我只是用cxFreeze 4.3.1来构建我的应用程序,问题就解决了。也可以在本地重建4.3.2并解决问题,但我没有尝试此解决方案。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Matplotlib 和 Pyplot 的导入问题(Python / Tkinter)

导入matplotlib和matplotlib.pyplot有什么区别?

使用网状在Rstudio中导入matplotlib.pyplot

使用Geany IDE导入matplotlib.pyplot时出错

使用anaconda在Visual Studio代码上导入matplotlib的pyplot失败

无法导入“ matplotlib.pyplot”

如何使用matplotlib和pyplot正确实现QThread

使用pandas和matplotlib.pyplot创建图例

在matplotlib.pyplot和numpy中递减

在哪种情况下使用了两种-matplotlib.pyplot.imshow()和matplotlib.pyplot.show()?

导入matplotlib.pyplot-fc-list挂起

PyCharm导入matplotlib.pyplot显示错误

导入matplotlib.pyplot作为plt失败

使用Julia和PyPlot绘制球体

是“从matplotlib将pyplot导入为plt” ==“从matplotlib.pyplot导入为plt”?

导入matplotlib.pyplot时发生Matplotlib TypeError

matplotlib pyplot - 如何组合多个 y 轴和多个图

Matplotlib pyplot-刻度控制和显示日期

使用matplotlib.pyplot,imshow()和savefig()以全分辨率进行绘制?

cxFreeze和Jaraco:ImportError

无法在virtualenv中“将matplotlib.pyplot导入为plt”

尝试导入Matplotlib.pyplot时,获取“ UnicodeDecodeError”

导入matplotlib.pyplot时出现随机Nan错误

无法在jupyter中导入matplotlib.pyplot(但不是ipython)

没有conda无法导入'matplotlib.pyplot'

导入matplotlib.pyplot时嵌入式python崩溃

使用 BeautifulSoup 从网站导入表格

使用Django Pandas和Pyplot分析CSV文件

在对数pyplot中同时使用yticks和ylim