Building a cx_Freeze exe with Numpy for Python

I am trying to create a basic exe using cx_Freeze. It works for .py programs that don't have numpy, but I can't seem to get one of them correct 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:\Python32\Scripts\dist>Assignment4_5.exe
           Traceback (most recent call last):
     File "C:\Python32\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 2
     7, in <module>
     exec(code, m.__dict__)
     File "c:\Python32\Assignment4_5.py", line 6, in <module>
     import numpy as np
     File "C:\Python32\lib\site-packages\numpy\__init__.py", line 137, in <module>
     from . import add_newdocs
     File "C:\Python32\lib\site-packages\numpy\add_newdocs.py", line 9, in <module>

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

   c:\Python32\Scripts\dist>

      

Setup.py:

   from cx_Freeze import setup, Executable

   includeDependencies = []

   setup(
        name = "Assignment4_5PythonExe",
        version = "0.1",
        description = "Sort Methods",
        executables = [Executable("Assignment4_5.py")]
        )

      

+6


source to share


2 answers


This is a bug in cx_Freeze - it does not automatically determine what the module should copy numpy.lib.format

. This has already been fixed in the developer release , so if you can try this it should work.

Otherwise, you will need to specify what numpy.lib.format

should be included in your setup.py

. The line will look something like this:



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

      

See also the documentation .

+5


source


Numpy seems to confuse cx_Freeze a bit, so you need to declare this explicitly. As stated in the documentation

Here's your solution:



   from cx_Freeze import setup, Executable

   build_exe_options = {"packages": ["numpy"]}

   setup(
        name = "Assignment4_5PythonExe",
        version = "0.1",
        description = "Sort Methods",
        options = {"build_exe": build_exe_options},
        executables = [Executable("Assignment4_5.py")]
        )

      

+5


source







All Articles