本文介绍了cx_freeze无法使用 pandas 库创建exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用cx_freeze和Pandas库创建exe时遇到问题.我看到许多其他人都遇到了numPy的问题,但我能够成功引入numPy.我最大的痛点是熊猫.熊猫里有什么可能导致失败的东西吗?

Having problems creating exe using cx_freeze with a Pandas library. I have seen lots of others having issues with numPy but I was able to successfully bring in numPy. My big pain point has been Pandas. Is there anything in Pandas that might be causing to fail?

设置文件

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)

如果我从安装程序文件和代码段中删除了熊猫并离开了Numpy,则我有一个可执行的可执行文件.有人遇到这个问题吗? exe被创建,但是没有任何支持文件被添加到构建目录.打开exe后,程序立即崩溃.

If I remove Pandas from my Setup file and snippet and leave Numpy I have a functional executable. Anybody run into this issue? The exe gets created but none of the supporting files is added to the build directory. On open of the exe, I the program immediately crashes.

我正在anaconda Windows 8计算机上运行python27 64位.

I am running python27 64 bit on anaconda windows 8 machine.

推荐答案

将以下内容添加到您的build_exe_options中:

Add the following to your 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.

I looked at boto/compat.py and did not see a sys module being imported. By excluding the above list of modules, boto/compat.py is still included.

排除"boto.compat.sys"和"boto.compat._sre"之后,出现以下错误:

After excluding 'boto.compat.sys' and 'boto.compat._sre', I got the following error:

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.parent.path访问module:

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自动将其拾取.排除"boto.compat._json"就可以了.

NOTE: _json.so is the built in json module. This means putting it in the includes specifically should include it. I did not since other packages caused cx_freeze to pick it up automatically. Excluding 'boto.compat._json' did the trick.

我重复了这一遍,直到整个过程都完成了.我确认所有基本模块均已被cx_freeze(_sre,_json,_locale,_struct,数组)拾取,因此无需手动将其添加到包含中.

I repeated this until I the whole thing built. I confirmed all base modules were picked up by cx_freeze (_sre, _json, _locale, _struct, array) so I did not need to add them manually to includes.

因此,您更新后的脚本将如下所示:

So, your updated script will look like:

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")]
)

这篇关于cx_freeze无法使用 pandas 库创建exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 10:26