Creating cx_Freeze exe with Numpy for Python

Go To


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

When I go to run the exe it says:

           Traceback (most recent call last):
     File "C:\Python32\lib\site-packages\cx_Freeze\initscripts\", line 2
     7, in <module>
     exec(code, m.__dict__)
     File "c:\Python32\", line 6, in <module>
     import numpy as np
     File "C:\Python32\lib\site-packages\numpy\", line 137, in <module>
     from . import add_newdocs
     File "C:\Python32\lib\site-packages\numpy\", line 9, in <module>

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


   from cx_Freeze import setup, Executable

   includeDependencies = []

        name = "Assignment4_5PythonExe",
        version = "0.1",
        description = "Sort Methods",
        executables = [Executable("")]
2012-04-04 05:43
by TMan
Try pyinstaller instead. It will handle libraries like numpy, matplotlib, etc with far less headache, i.m.o - Joe Kington 2012-04-04 12:54
@JoeKington: But PyInstaller won't work with c:\Python32...

@TMan: it looks like it's failing to copy the module numpy.lib.format. I'll look at why that is - Thomas K 2012-04-04 17:58

@ThomasK - Good point. I missed that he was using python3 - Joe Kington 2012-04-04 18:13
I wish I had python 3, then py2exe would solve my problem... Fortunately stuck with 2 for my problem.. - ntg 2016-08-22 10:02


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 The line will look something like this:

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

See also the documentation.

2012-04-04 21:10
by Thomas K
Hey, how would I edit the cxfreeze with this addition? wouldn't that enable the standard cxfreeze script located in Python36/Scripts to convert numpy scripts also - Artur Müller Romanov 2018-07-20 14:18


Numpy seems to be a little confusing to cx_Freeze so you need to declare it explicitly. As referenced in the docs

Here is your solution:

   from cx_Freeze import setup, Executable

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

        name = "Assignment4_5PythonExe",
        version = "0.1",
        description = "Sort Methods",
        options = {"build_exe": build_exe_options},
        executables = [Executable("")]
2017-06-07 14:32
by blackmore5
I can confirm this works @blackmore5. Note that my build options reads: buildexeoptions = {"include_files": ["tcl86t.dll", "tk86t.dll"], "packages": ["numpy"] - Lionel Yu 2018-09-18 18:53