使用Numpy for Python创建cx_Freeze exe

前端之家收集整理的这篇文章主要介绍了使用Numpy for Python创建cx_Freeze exe前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图使用cx_Freeze创建一个基本的exe.它适用于没有numpy的.py程序,但我无法通过numpy正确制作.

*有想法该怎么解决这个吗?我需要在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",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")]
        )

解决方法

这是cx_Freeze中的一个错误 – 它不会自动检测到它应该复制模块numpy.lib.format.它已经在 development version中修复了,所以如果你能够尝试它,它应该可以工作.

否则,您需要指定numpy.lib.format需要包含在setup.py中.该行看起来像这样:

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

另见the documentation.

原文链接:https://www.f2er.com/python/186686.html

猜你在找的Python相关文章