Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
544 views
in Technique[技术] by (71.8m points)

python - cx_freeze fails to create exe with pandas library

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?

Setup file

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

Code snippet showing what I am pulling in

import pyodbc
import numpy as np
import pandas.io.sql as psql
from pandas import  DataFrame, Series, date_range
import datetime

print("Hello World")

Here is the Error log I get

> Stamped: buildexe.win-amd64-2.7appName.exe Traceback (most recent
> call last):   File "setup.py", line 17, in <module>
>     executables = [Executable("pyodbc.py")]   File "C:UsersDengarAppDataLocalContinuumAnacondalibsite-packagescx_Freezedist.py",
> line 365, in setup
>     distutils.core.setup(**attrs)   File "C:UsersDengarAppDataLocalContinuumAnacondalibdistutilscore.py",
> line 152, in setup
>     dist.run_commands()   File "C:UsersDengarAppDataLocalContinuumAnacondalibdistutilsdist.py",
> line 953, in run_commands
>     self.run_command(cmd)   File "C:UsersDengarAppDataLocalContinuumAnacondalibdistutilsdist.py",
> line 972, in run_command
>     cmd_obj.run()   File "C:UsersDengarAppDataLocalContinuumAnacondalibdistutilscommanduild.py",
> line 127, in run
>     self.run_command(cmd_name)   File "C:UsersDengarAppDataLocalContinuumAnacondalibdistutilscmd.py",
> line 326, in run_command
>     self.distribution.run_command(command)   File "C:UsersDengarAppDataLocalContinuumAnacondalibdistutilsdist.py",
> line 972, in run_command
>     cmd_obj.run()   File "C:UsersDengarAppDataLocalContinuumAnacondalibsite-packagescx_Freezedist.py",
> line 235, in run
>     freezer.Freeze()   File "C:UsersDengarAppDataLocalContinuumAnacondalibsite-packagescx_Freezefreezer.py",
> line 582, in Freeze
>     self.compress, self.copyDependentFiles)   File "C:UsersDengarAppDataLocalContinuumAnacondalibsite-packagescx_Freezefreezer.py",
> line 492, in _WriteModules
>     module.Create(finder)   File "C:UsersDengarAppDataLocalContinuumAnacondalibsite-packagescx_Freezefreezer.py",
> line 714, in Create
>     module.file, module.name) cx_Freeze.freezer.ConfigError: no file named sys (for module boto.compat.sys)

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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'],
}

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.

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

I ran ipython and then typed:

In [1]: pdb
Automatic pdb calling has been turned ON

In [2]: run setup.py build

To get access to module from module.parent.path:

ipdb> module
<Module name='boto.compat._json', file='/Users/king/virtual_envs/py27/lib/python2.7/lib-dynload/_json.so'>

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.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...