Python cx_Freeze导入错误“没有名为humanize的模块”

时间:2017-07-07 13:19:10

标签: python exe cx-freeze

    C:\WINDOWS\system32>py C:\Users\Lenovo\Desktop\RPGTxtGame\setup.py build
running build
running build_exe
Traceback (most recent call last):
  File "C:\Users\Lenovo\Desktop\RPGTxtGame\setup.py", line 5, in <module>
    cx_Freeze.setup( name = "downloads", version = "1.0", options = {"build_exe": {"packages": ["errno", "os", "re", "stat", "subprocess","collections", "pprint","shutil", "humanize","pycallgraph"], "include_files": []}}, executables = exe )
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\dist.py", line 349, in setup
    distutils.core.setup(**attrs)
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\distutils\command\build.py", line 135, in run
    self.run_command(cmd_name)
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\dist.py", line 219, in run
    freezer.Freeze()
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\freezer.py", line 621, in Freeze
    self.finder = self._GetModuleFinder()
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\freezer.py", line 340, in _GetModuleFinder
    finder.IncludePackage(name)
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 653, in IncludePackage
    module = self._ImportModule(name, deferredImports)
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 350, in _ImportModule
    raise ImportError("No module named %r" % name)
ImportError: No module named 'humanize'

嗨,我试图从我的python项目创建一个可执行文件。尽管

,但是cx_Freeze仍然存在这个错误

我也尝试了pyinstaller但是那个与python 3.6不兼容

我的setup.py脚本是

import cx_Freeze

exe = [cx_Freeze.Executable("main.py")]

cx_Freeze.setup( name = "downloads", version = "1.0", options = {"build_exe": {"packages": ["errno", "os", "re", "stat", "subprocess","collections", "pprint","shutil", "humanize","pycallgraph"], "include_files": []}}, executables = exe )

你能帮帮我吗?

2 个答案:

答案 0 :(得分:0)

我会这样做。

from cx_Freeze import setup, Executable

build_exe_options = {"packages": ["errno", "os", "re", "stat", "subprocess","collections", "pprint","shutil", "humanize","pycallgraph"]}

setup( name = "downloads", 
       version = "1.0", 
       options = {"build_exe": build_exe_options}, 
       description = "Your description here.",
       executables = [Executable("main.py")])

作为旁注,根据您的环境,您不需要明确包含诸如“os”,“re”,“shutil”或任何其他标准库模块之类的内容,因为cx_Freeze应该能够自动查找和导入这些模块。

还要确保在“main.py”脚本中导入“humanize”包。

答案 1 :(得分:0)

好的,我通过完全避开setup.py来修复。

Official documentation

还有另一种方法

打字..

cxfreeze main.py
cmd中的

对我有用