我在2013年9月基本上和这个人有同样的问题。
相关问题: Cx_freeze with lxml.html TypeError(有人通过编辑cx-freeze代码找到了修复,但没有深入解释),cx-freeze doesn't find all dependencies(不确定如何在Linux中打开鸡蛋)
在我获得50个声望之前,我不被允许评论,所以我发布了这个帖子。我正在使用4.3.1的cx_freeze来冻结以下模块:
import sys
import getopt
from time import gmtime, strftime, time
from os.path import exists
from lxml import etree
我的setup.py脚本:
import sys
from cx_Freeze import setup, Executable
#build_exe_options = {"packages": ["sys","getopt","time","os","lxml"]}
build_exe_options = {"packages": ["sys","getopt","time","os","lxml","BeautifulSoup","lxml.html.soupparser","lxml.html.html5parser","lxml.html.diff","lxml.ElementInclude"]}
setup(
name = "cmpxml",
version = "r13",
description = "",
options = {"build_exe": build_exe_options},
executables = [ Executable("cmpxml.py", base = None) ] )
我跑
python setup.py build_exe
或
python setup.py build
并收到以下消息:
? cjkcodecs.aliases imported from BeautifulSoup
? html.entities imported from lxml.html.soupparser
? html5lib imported from lxml.html.html5parser
? iconv_codec imported from BeautifulSoup
? lxml.html.escape imported from lxml.html.diff
? urllib.parse imported from lxml.ElementInclude
? urllib.request imported from lxml.ElementInclude
运行我编译的程序时,尝试导入lxml时失败,所以我觉得上述消息对于调试编译至关重要。
我做错了什么或这是cx-freeze的问题?我的LXML模块是使用pip安装的(所以不需要PYTHONPATH)我在Ubuntu 13.10上使用python 2.7。
Nuitka 0.4.7:
其他问题但相关:巧合的是,我也遇到了与Nuitka类似的问题。
/usr/share/nuitka/bin/nuitka cmpxml.py --exe --recurse-all --execute
将正确编译,但在运行./cmpxml时,将无法找到lxml模块。
PyInstaller 2.1:
还尝试使用带有hooks目录的pyinstaller,其中包含hook-lxml.etree.py,hook-lxml.objectify.py,hook-xml.etree.cElementTree.py并运行
pyinstaller --additional-hooks-dir=hooks/ cmpxml.py
在dist / cmpxml / cmpxml中运行二进制文件时仍无法检测到lxml。构建目录中的警告文件包含这些缺少的模块,从pyinstaller git下载所有钩子并没有解决问题。
$ cat build/cmpxml_noetree/warncmpxml_noetree.txt
W: no module named msvcrt (conditional import by subprocess)
W: no module named msvcrt (delayed import by getpass)
W: no module named _dummy_threading (top-level import by dummy_threading)
W: no module named cl (delayed, conditional import by aifc)
W: no module named rourl2path (conditional import by urllib)
W: no module named nt (conditional import by __main__)
W: no module named nt (conditional import by pyi_os_path)
W: no module named _subprocess (conditional import by subprocess)
W: no module named cl (delayed import by aifc)
W: no module named _scproxy (conditional import by urllib)
W: no module named org (top-level import by pickle)
W: no module named EasyDialogs (conditional import by getpass)
W: no module named SOCKS (top-level import by ftplib)
W: no module named _winreg (delayed import by urllib)
W: no module named nt (top-level import by ntpath)
W: no module named msvcrt (conditional import by getpass)
W: no module named _winreg (top-level import by mimetypes)
W: no module named org (top-level import by copy)
W: no module named _emx_link (conditional import by os)
奇怪的是这个警告文件中甚至没有提到lxml。出于某种原因,它不包括在内。
任何帮助将不胜感激。 Nuitka,pyinstaller,冻结,cx-freeze,似乎都是伟大的程序,但似乎并不适合我。
答案 0 :(得分:1)
我的一位朋友告诉我,问题是由于缺乏进口检查模块。
用于编译上述内容的cx-freeze的正确命令:
cxfreeze cmpxml.py --target-dir cmpxml --include-modules=sys,getopt,time,os,inspect,lxml.etree,lxml._elementpath,gzip,encodings.utf_8,encodings.ascii
答案 1 :(得分:0)
除了那些用Google搜索这个问题的人。 OP使用Nuitka 4.3.1,但在Nuitka 0.5.1中,问题似乎是固定的http://nuitka.net/posts/nuitka-release-051.html