通过cx_freeze将带有BeautifulSoup的脚本转换为.exe时,出现错误

时间:2014-09-24 15:18:35

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

from bs4 import BeautifulSoup
html = '<div class="fun">something fun</div>'
soup = BeautifulSoup(html)
print(soup.find('div').string)

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

导入sys

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.

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

没关系,我间接地解决了。 我选择使用py2exe,它可以正常工作。