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
483 views
in Technique[技术] by (71.8m points)

Creating cx_Freeze exe with Numpy for Python

Im trying to create a basic exe using cx_Freeze. It works for .py programs that don't have numpy but I can't get one made correctly with numpy.

*Any ideas on how to fix this? is there something i need to include in my setup.py?

When I go to run the exe it says:

           c:Python32Scriptsdist>Assignment4_5.exe
           Traceback (most recent call last):
     File "C:Python32libsite-packagescx_FreezeinitscriptsConsole3.py", line 2
     7, in <module>
     exec(code, m.__dict__)
     File "c:Python32Assignment4_5.py", line 6, in <module>
     import numpy as np
     File "C:Python32libsite-packages
umpy\__init__.py", line 137, in <module>
     from . import add_newdocs
     File "C:Python32libsite-packages
umpyadd_newdocs.py", line 9, in <module>

     from numpy.lib import add_newdoc
     File "C:Python32libsite-packages
umpylib\__init__.py", line 17, in <modul
     e>
    from .npyio import *
    File "C:Python32libsite-packages
umpylib
pyio.py", line 6, in <module>
    from . import format
    ImportError: cannot import name format

   c:Python32Scriptsdist>

Setup.py:

   from cx_Freeze import setup, Executable

   includeDependencies = []

   setup(
        name = "Assignment4_5PythonExe",
        version = "0.1",
        description = "Sort Methods",
        executables = [Executable("Assignment4_5.py")]
        )
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

This is a bug in cx_Freeze - it doesn't automatically detect that it should copy the module numpy.lib.format. It's already fixed in the development version, so if you're in a position to try that, it should work.

Otherwise, you'll need to specify that numpy.lib.format needs to be included in your setup.py. The line will look something like this:

options = {"build_exe": {"packages": ["numpy.lib.format"]}},

See also the documentation.


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

...