【发布时间】:2015-09-29 16:12:35
【问题描述】:
总结:
我有一个 wxPython/bs4 应用程序,我正在使用 cx_freeze 将它构建到一个 exe 中。
构建成功且没有错误,但尝试运行 EXE 会导致来自 BeautifulSoup4 的 FeatureNotFound 错误。它抱怨我没有安装我的 lxml 库。
我已经将程序剥离到它的最小状态,但仍然得到错误。
有没有其他人使用 cx_freeze 成功构建了 bs4 应用程序?
请查看下面的详细信息,如果您有任何想法,请告诉我。
谢谢,
详情
完整的错误回溯:
我已将应用程序简化为最基本的状态,但仍然出现错误。我在 Python 3.4 上也遇到了同样的错误。
Traceback (most recent call last):
File "C:\WinPython27\python-2.6.7\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
File "test.py", line 6, in <module>
File "C:\WinPython27\python-2.6.7\lib\site-packages\bs4\__init__.py", line 152, in __init__
% ",".join(feautres))
FeatureNotFound: Couldn't find a tree builder with the features you requested: xml. Do you need to install a parser library?
我已经尝试过的:
我发现有人说我需要在构建脚本中包含 lxml 及其依赖项:http://sourceforge.net/p/cx-freeze/mailman/message/27973651/(对于 SF 链接抱歉)。我试过了,但还是没有骰子。
注释掉soup = BeautifulSoup("<tag>value</tag>", 'xml') 行不会导致错误。
版本和文件:
版本:
- lxml 3.4.4
- BeautifulSoup4 4.3.2
- Python 2.7.6(32 位)和 Python 3.4.3(64 位)
- cx_Freeze 4.3.4
- wxPython 3.0-msw
- Windows 7 Professional SP1,64 位
test.py
此文件是仍然出现错误的简化应用程序。
# -*- coding: utf-8 -*-
from __future__ import print_function
from bs4 import BeautifulSoup
import wx
soup = BeautifulSoup("<tag>value</tag>", 'xml')
app = wx.App()
frame = wx.Frame(None, wx.ID_ANY, "test frame")
frame.Show()
app.MainLoop()
build_executables.py
这是我正在使用的(简化的)构建脚本。
# -*- coding: utf-8 -*-
from cx_Freeze import setup, Executable
build_exe_opts = {"silent": False, }
base = "Win32GUI"
exes_to_build = [Executable("test.py", base=base),
]
setup(
name="test",
version="0.0.1",
description="FTI test program editor and diff tool.",
options={"build_exe": build_exe_opts},
executables=exes_to_build,
)
cx_freeze 日志
我不会在此处包含整个日志,但我确实运行了python build_executables.py build >> C:\temp\build_log.txt,因此可以查找任何需要的内容。
以下是其中包含“lxml”的行:
Name File
---- ----
P bs4 C:\WinPython27\python-2.7.6\lib\site-packages\bs4\__init__.py
P bs4.builder C:\WinPython27\python-2.7.6\lib\site-packages\bs4\builder\__init__.py
m bs4.builder._html5lib C:\WinPython27\python-2.7.6\lib\site-packages\bs4\builder\_html5lib.py
m bs4.builder._htmlparser C:\WinPython27\python-2.7.6\lib\site-packages\bs4\builder\_htmlparser.py
m bs4.builder._lxml C:\WinPython27\python-2.7.6\lib\site-packages\bs4\builder\_lxml.py
m bs4.dammit C:\WinPython27\python-2.7.6\lib\site-packages\bs4\dammit.py
m bs4.element C:\WinPython27\python-2.7.6\lib\site-packages\bs4\element.py
...
P lxml C:\WinPython27\python-2.7.6\lib\site-packages\lxml\__init__.py
m lxml.etree C:\WinPython27\python-2.7.6\lib\site-packages\lxml\etree.pyd
...
copying C:\WinPython27\python-2.7.6\lib\site-packages\lxml\etree.pyd -> build\exe.win32-2.7\lxml.etree.pyd
构建成功,没有错误。
【问题讨论】:
-
如果您在代码中添加
import lxml,它是否会显示另一条错误消息? LXML 可能依赖于其他东西。 -
@ThomasK 遗憾的是,这不起作用。它在执行时会导致相同的错误。
标签: python beautifulsoup wxpython lxml cx-freeze