0
from bs4 import BeautifulSoup
html = '<div class="fun">something fun</div>'
soup = BeautifulSoup(html)
print(soup.find('div').string)
這是代碼。我用cxfreeze使其可執行:當通過cx_freeze將使用BeautifulSoup的腳本轉換爲.exe時,出現錯誤
進口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.
任何幫助將不勝感激。
當cx_Freeze是針對不同的小版本Python構建的,而不是您用來凍結的時候出現這個錯誤。 – 2014-09-24 16:56:27
python版本是3.3.5,而cx_freeze是由easy_install安裝的。它是4.3.3。我如何解決這個問題? – Yearner 2014-09-25 01:21:03