创建cx_Freeze EXE与NumPy的为Python创建cx_Freeze EXE与NumPy

2019-05-12 03:15发布

我试着去创建一个使用cx_Freeze一个基本的exe文件。 它适用于那些没有numpy的,但我不能让一个与numpy的正确无误的.py程序。

*有想法该怎么解决这个吗? 是不是我需要在我setup.py包括?

当我去运行exe它说:

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

Answer 1:

这是cx_Freeze错误-它不会自动检测到它应该复制的模块numpy.lib.format 。 它已经固定在开发版本 ,所以如果你在一个位置,尝试的时候,它应该工作。

否则,你需要指定numpy.lib.format需要包含在你的setup.py 。 该生产线将是这个样子:

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

另请参见文档 。



Answer 2:

NumPy的似乎有点混乱,cx_Freeze所以你需要明确申报。 如参考文档

这里是您的解决方案:

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


文章来源: Creating cx_Freeze exe with Numpy for Python