【问题标题】:When convert a script with BeautifulSoup to .exe by cx_freeze, I get an error通过 cx_freeze 将带有 BeautifulSoup 的脚本转换为 .exe 时,出现错误
【发布时间】:2014-09-24 15:18:35
【问题描述】:
from bs4 import BeautifulSoup
html = '<div class="fun">something fun</div>'
soup = BeautifulSoup(html)
print(soup.find('div').string)

这是代码。我使用 cxfreeze 使其可执行:

导入系统

from cx_Freeze import setup, Executable
script = 'test'
setup(  name = "{}".format(script),
        version = "1.0.0",
        author = 'abraham',
        options = {'build_exe': {'init_script':'Console'}},
        executables = [Executable('{}.py'.format(script))])

But when I try to run it in shell, I get this error:
<pre>
G:\>G:\build\exe.win32-3.3\test.exe
Traceback (most recent call last):
  File "E:\Python33\lib\site-packages\cx_freeze-4.3.3-py3.3-win32.egg\cx_Freeze\initscripts
\Console.py", line 27, in <module>
    exec(code, m.__dict__)
  File "test.py", line 1, in <module>
    from bs4 import BeautifulSoup
  File "c:\python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1567, in _find_and_load
  File "c:\python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1534, in _find_and_load_unl
ocked
  File "E:\Python33\lib\site-packages\bs4\__init__.py", line 30, in <module>
    from .builder import builder_registry, ParserRejectedMarkup
  File "c:\python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1567, in _find_and_load
  File "c:\python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1534, in _find_and_load_unl
ocked
  File "E:\Python33\lib\site-packages\bs4\builder\__init__.py", line 308, in <module>
    from . import _htmlparser
  File "c:\python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1616, in _handle_fromlist
  File "c:\python\32-bit\3.3\lib\importlib\_bootstrap.py", line 313, in _call_with_frames_r
emoved
  File "c:\python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1567, in _find_and_load
  File "c:\python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1534, in _find_and_load_unl
ocked
  File "E:\Python33\lib\site-packages\bs4\builder\_htmlparser.py", line 7, in <module>
    from html.parser import (
  File "c:\python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1567, in _find_and_load
  File "c:\python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1534, in _find_and_load_unl
ocked
  File "E:\Python33\lib\html\parser.py", line 70, in <module>
    """, re.VERBOSE)
  File "c:\python\32-bit\3.3\lib\re.py", line 214, in compile
  File "c:\python\32-bit\3.3\lib\re.py", line 281, in _compile
  File "c:\python\32-bit\3.3\lib\sre_compile.py", line 498, in compile
  File "c:\python\32-bit\3.3\lib\sre_compile.py", line 483, in _code
  File "c:\python\32-bit\3.3\lib\sre_compile.py", line 75, in _compile
  File "c:\python\32-bit\3.3\lib\sre_compile.py", line 362, in _simple
sre_constants.error: nothing to repeat

顺便说一句,我使用 mingw32 作为编译器安装了 BeautifulSoup。 并且cx_freeze提到可能缺少一些模块,如下:

Missing modules:
? _dummy_threading imported from dummy_threading
? _emx_link imported from os
? cchardet imported from bs4.dammit
? ce imported from os
? chardet imported from bs4.dammit
? doctest imported from heapq
? getopt imported from base64, quopri
? html5lib imported from bs4.builder._html5lib
? html5lib.constants imported from bs4.builder._html5lib
? iconv_codec imported from bs4.dammit
? lxml imported from bs4.builder._lxml
? org.python.core imported from copy
? os.path imported from os
? os2 imported from os
? os2emxpath imported from os
? posix imported from os
? pwd imported from posixpath
? subprocess imported from os
This is not necessarily a problem - the modules may not be needed on this platform.

任何帮助将不胜感激。

【问题讨论】:

  • 当 cx_Freeze 是针对与您用于冻结的 Python 不同的次要版本构建时,会出现该错误。
  • python版本为3.3.5,cx_freeze由easy_install安装。它是 4.3.3。我该如何解决?

标签: python-3.x beautifulsoup cx-freeze


【解决方案1】:

没关系,我间接解决了。 我选择使用 py2exe 来代替它,它工作得很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-15
    • 1970-01-01
    相关资源
    最近更新 更多