使用带有Pandas库的cx_freeze创建exe时遇到问题。我见过很多其他人都有numPy的问题,但我能成功引入numPy。我最大的痛点就是熊猫。熊猫中有什么东西可能导致失败吗?
设置文件
from cx_Freeze import setup, Executable
build_exe_options = {
"includes": ['numpy', 'pandas'],
"packages": [],
'excludes' : [],
"include_files": []}
setup(
name = "appName",
version = "0.1",
description = "",
author = "Dengar",
options = {"build_exe": build_exe_options},
executables = [Executable("appName.py")]
)
代码段 显示了我的内容
import pyodbc
import numpy as np
import pandas.io.sql as psql
from pandas import DataFrame, Series, date_range
import datetime
print("Hello World")
以下是我收到的错误日志
> Stamped: build\exe.win-amd64-2.7\appName.exe Traceback (most recent > call last): File "setup.py", line 17, in <module> > executables = [Executable("pyodbc.py")] File "C:\Users\Dengar\AppData\Local\Continuum\Anaconda\lib\site-packages\cx_Freeze\dist.py", > line 365, in setup > distutils.core.setup(**attrs) File "C:\Users\Dengar\AppData\Local\Continuum\Anaconda\lib\distutils\core.py", > line 152, in setup > dist.run_commands() File "C:\Users\Dengar\AppData\Local\Continuum\Anaconda\lib\distutils\dist.py", > line 953, in run_commands > self.run_command(cmd) File "C:\Users\Dengar\AppData\Local\Continuum\Anaconda\lib\distutils\dist.py", > line 972, in run_command > cmd_obj.run() File "C:\Users\Dengar\AppData\Local\Continuum\Anaconda\lib\distutils\command\build.py", > line 127, in run > self.run_command(cmd_name) File "C:\Users\Dengar\AppData\Local\Continuum\Anaconda\lib\distutils\cmd.py", > line 326, in run_command > self.distribution.run_command(command) File "C:\Users\Dengar\AppData\Local\Continuum\Anaconda\lib\distutils\dist.py", > line 972, in run_command > cmd_obj.run() File "C:\Users\Dengar\AppData\Local\Continuum\Anaconda\lib\site-packages\cx_Freeze\dist.py", > line 235, in run > freezer.Freeze() File "C:\Users\Dengar\AppData\Local\Continuum\Anaconda\lib\site-packages\cx_Freeze\freezer.py", > line 582, in Freeze > self.compress, self.copyDependentFiles) File "C:\Users\Dengar\AppData\Local\Continuum\Anaconda\lib\site-packages\cx_Freeze\freezer.py", > line 492, in _WriteModules > module.Create(finder) File "C:\Users\Dengar\AppData\Local\Continuum\Anaconda\lib\site-packages\cx_Freeze\freezer.py", > line 714, in Create > module.file, module.name) cx_Freeze.freezer.ConfigError: no file named sys (for module boto.compat.sys)
如果我从我的安装文件和代码段中删除Pandas并离开Numpy我有一个功能可执行文件。有人遇到过这个问题吗? exe已创建,但没有任何支持文件添加到构建目录。在打开exe时,程序立即崩溃。
我在anaconda windows 8机器上运行64位python27。
答案 0 :(得分:4)
将以下内容添加到build_exe_options:
'build_exe': {
'excludes': ['boto.compat.sys',
'boto.compat._sre',
'boto.compat._json',
'boto.compat._locale',
'boto.compat._struct',
'boto.compat.array'],
}
我查看了boto / compat.py并没有看到正在导入的sys模块。通过排除上面的模块列表,仍然包括boto / compat.py。
排除&#39; boto.compat.sys&#39;和&#39; boto.compat._sre&#39;,我收到以下错误:
Traceback (most recent call last):
File "setup.py", line 31, in <module>
executables=executables
File "/Users/king/virtual_envs/py27/lib/python2.7/site-packages/cx_Freeze/dist.py", line 362, in setup
distutils.core.setup(**attrs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build.py", line 127, in run
self.run_command(cmd_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/Users/king/virtual_envs/py27/lib/python2.7/site-packages/cx_Freeze/dist.py", line 232, in run
freezer.Freeze()
File "/Users/king/virtual_envs/py27/lib/python2.7/site-packages/cx_Freeze/freezer.py", line 610, in Freeze
self.compress, self.copyDependentFiles)
File "/Users/king/virtual_envs/py27/lib/python2.7/site-packages/cx_Freeze/freezer.py", line 586, in _WriteModules
path = os.pathsep.join([origPath] + module.parent.path)
TypeError: can only concatenate list (not "NoneType") to list
我跑ipython
然后输入:
In [1]: pdb
Automatic pdb calling has been turned ON
In [2]: run setup.py build
要从module
访问module.parent.path
:
ipdb> module
<Module name='boto.compat._json', file='/Users/king/virtual_envs/py27/lib/python2.7/lib-dynload/_json.so'>
注意:_json.so是内置的json模块。这意味着将它放入包含中应该包括它。我没有,因为其他软件包导致cx_freeze自动获取它。排除&#39; boto.compat._json&#39;做了伎俩。
我重复这个,直到我整个事情都建好了。我确认所有基本模块都是由cx_freeze(_sre,_json,_locale,_struct,array)选中的,因此我不需要手动将它们添加到包含。
因此,您更新的脚本将如下所示:
from cx_Freeze import setup, Executable
build_exe_options = {
"includes": ['numpy', 'pandas'],
"packages": [],
'excludes' : ['boto.compat.sys',
'boto.compat._sre',
'boto.compat._json',
'boto.compat._locale',
'boto.compat._struct',
'boto.compat.array'],
"include_files": []}
setup(
name = "appName",
version = "0.1",
description = "",
author = "Dengar",
options = {"build_exe": build_exe_options},
executables = [Executable("appName.py")]
)
答案 1 :(得分:1)
以下内容可帮助您解决此问题(并可能导致您找到下一个缺少的依赖项;)
检查freeze.py的代码,有一个未检查的情况,所以我对freezer.py进行了以下更改:
第600行,来自
try:
if module.parent is not None:
path = os.pathsep.join([origPath] + module.parent.path)
os.environ["PATH"] = path
self._CopyFile(module.file, target, copyDependentFiles)
finally:
os.environ["PATH"] = origPath
为:
try:
if module.parent is not None:
if module.parent.path is not None:
path = os.pathsep.join([origPath] + module.parent.path)
os.environ["PATH"] = path
self._CopyFile(module.file, target, copyDependentFiles)
else:
path = os.pathsep.join([origPath, os.path.dirname(module.parent.file)])
os.environ["PATH"] = path
print '========================================================'
finally:
os.environ["PATH"] = origPath