cx_Freeze 构建错误?

Posted

技术标签:

【中文标题】cx_Freeze 构建错误?【英文标题】:cx_Freeze build error? 【发布时间】:2017-10-06 15:35:50 【问题描述】:

我正在尝试从 python、flask 和 boto3 应用程序创建二进制文件。我在运行pip install cx_Freeze 命令时也遇到了问题。我收到以下错误:

似乎没有获取正确的系统库。另外,任何人都可以建议任何工具将 python 应用程序打包成二进制文件吗?

  Failed building wheel for cx-Freeze
  Running setup.py clean for cx-Freeze
Failed to build cx-Freeze
Installing collected packages: cx-Freeze
  Running setup.py install for cx-Freeze ... error
    Complete output from command /home/shaswat.g/.virtualenvs/flask_app/bin/python -u -c "import setuptools,     tokenize;__file__='/tmp/pip-build-yLvkz9/cx-Freeze/setup.py';f=getattr(tokenize, 'open',     open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install     --record /tmp/pip-kKRaSM-record/install-record.txt --single-version-externally-managed --compile     --install-headers /home/shaswat.g/.virtualenvs/flask_app/include/site/python2.7/cx-Freeze:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    creating build/lib.linux-x86_64-2.7/cx_Freeze
    copying cx_Freeze/dist.py -> build/lib.linux-x86_64-2.7/cx_Freeze
    copying cx_Freeze/main.py -> build/lib.linux-x86_64-2.7/cx_Freeze
    copying cx_Freeze/common.py -> build/lib.linux-x86_64-2.7/cx_Freeze
    copying cx_Freeze/__init__.py -> build/lib.linux-x86_64-2.7/cx_Freeze
    copying cx_Freeze/macdist.py -> build/lib.linux-x86_64-2.7/cx_Freeze
    copying cx_Freeze/finder.py -> build/lib.linux-x86_64-2.7/cx_Freeze
    copying cx_Freeze/setupwriter.py -> build/lib.linux-x86_64-2.7/cx_Freeze
    copying cx_Freeze/windist.py -> build/lib.linux-x86_64-2.7/cx_Freeze
    copying cx_Freeze/hooks.py -> build/lib.linux-x86_64-2.7/cx_Freeze
    copying cx_Freeze/freezer.py -> build/lib.linux-x86_64-2.7/cx_Freeze
    creating build/lib.linux-x86_64-2.7/cx_Freeze/initscripts
    copying cx_Freeze/initscripts/SharedLibSource.py -> build/lib.linux-x86_64-2.7/cx_Freeze/initscripts
    copying cx_Freeze/initscripts/__startup__.py -> build/lib.linux-x86_64-2.7/cx_Freeze/initscripts
    copying cx_Freeze/initscripts/SharedLib.py -> build/lib.linux-x86_64-2.7/cx_Freeze/initscripts
    copying cx_Freeze/initscripts/ConsoleSetLibPath.py -> build/lib.linux-x86_64-2.7/cx_Freeze/initscripts
    copying cx_Freeze/initscripts/Console.py -> build/lib.linux-x86_64-2.7/cx_Freeze/initscripts
    creating build/lib.linux-x86_64-2.7/cx_Freeze/samples
    creating build/lib.linux-x86_64-2.7/cx_Freeze/samples/relimport
    copying cx_Freeze/samples/relimport/setup.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/relimport
    copying cx_Freeze/samples/relimport/relimport.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/relimport
    creating build/lib.linux-x86_64-2.7/cx_Freeze/samples/service
    copying cx_Freeze/samples/service/Config.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/service
    copying cx_Freeze/samples/service/setup.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/service
    copying cx_Freeze/samples/service/ServiceHandler.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/service
    creating build/lib.linux-x86_64-2.7/cx_Freeze/samples/openpyxl
    copying cx_Freeze/samples/openpyxl/setup.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/openpyxl
    copying cx_Freeze/samples/openpyxl/test_openpyxl.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/openpyxl
    creating build/lib.linux-x86_64-2.7/cx_Freeze/samples/simple
    copying cx_Freeze/samples/simple/hello.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/simple
    copying cx_Freeze/samples/simple/setup.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/simple
    creating build/lib.linux-x86_64-2.7/cx_Freeze/samples/matplotlib
    copying cx_Freeze/samples/matplotlib/setup.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/matplotlib
    copying cx_Freeze/samples/matplotlib/matplotlib_eg.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/    matplotlib
    creating build/lib.linux-x86_64-2.7/cx_Freeze/samples/PyQt4
    copying cx_Freeze/samples/PyQt4/setup.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/PyQt4
    copying cx_Freeze/samples/PyQt4/PyQt4app.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/PyQt4
    creating build/lib.linux-x86_64-2.7/cx_Freeze/samples/advanced
    copying cx_Freeze/samples/advanced/advanced_1.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/advanced
    copying cx_Freeze/samples/advanced/advanced_2.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/advanced
    copying cx_Freeze/samples/advanced/setup.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/advanced
    creating build/lib.linux-x86_64-2.7/cx_Freeze/samples/asmodule
    copying cx_Freeze/samples/asmodule/asmodule.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/asmodule
    copying cx_Freeze/samples/asmodule/setup.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/asmodule
    creating build/lib.linux-x86_64-2.7/cx_Freeze/samples/zope
    copying cx_Freeze/samples/zope/setup.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/zope
    copying cx_Freeze/samples/zope/qotd.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/zope
    creating build/lib.linux-x86_64-2.7/cx_Freeze/samples/Tkinter
    copying cx_Freeze/samples/Tkinter/setup.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/Tkinter
    copying cx_Freeze/samples/Tkinter/SimpleTkApp.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/Tkinter
    creating build/lib.linux-x86_64-2.7/cx_Freeze/samples/wx
    copying cx_Freeze/samples/wx/setup.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/wx
    copying cx_Freeze/samples/wx/wxapp.py -> build/lib.linux-x86_64-2.7/cx_Freeze/samples/wx
    running build_ext
    building 'cx_Freeze.util' extension
    creating build/temp.linux-x86_64-2.7
    creating build/temp.linux-x86_64-2.7/source
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing     -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-HVkOs2/python2.7-2.7.13=.     -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/util.c -o     build/temp.linux-x86_64-2.7/source/util.o
    x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing     -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/    python2.7-HVkOs2/python2.7-2.7.13=. -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro     -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-HVkOs2/python2.7-2.7.13=.     -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/source/util.o -o build/    lib.linux-x86_64-2.7/cx_Freeze/util.so
    creating build/temp.linux-x86_64-2.7/source/bases
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing     -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-HVkOs2/python2.7-2.7.13=.     -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/bases/    Console.c -o build/temp.linux-x86_64-2.7/source/bases/Console.o
    creating build/lib.linux-x86_64-2.7/cx_Freeze/bases
    x86_64-linux-gnu-gcc -pthread build/temp.linux-x86_64-2.7/source/bases/Console.o -L/usr/lib/python2.7/    config-x86_64-linux-gnu -lpython2.7 -o build/lib.linux-x86_64-2.7/cx_Freeze/bases/Console -Xlinker     -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions -lpthread -ldl -lutil -lm -L/usr/lib -lz -s
    /usr/bin/ld: cannot find -lz
    collect2: error: ld returned 1 exit status
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/home/shaswat.g/.virtualenvs/flask_app/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-yLvkz9/cx-Freeze/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-kKRaSM-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/shaswat.g/.virtualenvs/flask_app/include/site/python2.7/cx-Freeze" failed with error code 1 in /tmp/pip-build-yLvkz9/cx-Freeze/

【问题讨论】:

【参考方案1】:

做吧

sudo apt install zlib1g-dev

我试图安装cx-freeze 将一些python 代码转换为exe,但问题是/usr/bin/ld: cannot find -lz 就像你一样。获取的文件已压缩 (cx_Freeze-5.1.1.tar.gz),因此您需要 zlib。当然对于 python3 使用pip3

【讨论】:

也许你的意思是“sudo apt install zlib1g-dev”? 没错; pip 版本由于某种原因无法正常工作,但我可以发誓在我写这篇文章的时候它可以工作。 谢谢。 sudo apt 版本确实有效,但后来我不得不放弃尝试在 Python 中构建包。不过感谢您的意见,这很有帮助:)【参考方案2】:

pip 从不安装 system 库,它只关心 Python 库

看来你需要在安装 cx_Freeze 之前安装zlib

另一个生成二进制文件的工具是PyInstaller。

【讨论】:

似乎仍然无法编译我的代码。我正在制作的应用程序使用flask 和boto3,那么您能否指出我还需要哪些系统库?尽管这似乎完全是一个不同问题的主题。 我不知道。当我安装 Python 时,我的安装程序安装了所有必要的系统库。当我觉得我需要更多东西时,我会一一试验并安装所需的软件包。

以上是关于cx_Freeze 构建错误?的主要内容,如果未能解决你的问题,请参考以下文章

使用 cx_Freeze 构建 msi:ValueError:FCI 错误 1

cx_freeze 将项目构建为 .exe 文件,出现 numpy 导入错误

使用 cx_freeze 构建的 Exe 会为所需的包产生“找不到模块”错误

cx_freeze 的 exe 错误

.py 到 .exe 使用 cx_freeze 导致错误

Python 3.5.3 上的 cx_Freeze 错误