簡體   English   中英

Python cx_Freeze導入錯誤“沒有命名為人性化的模塊”

[英]Python cx_Freeze Import Error “No module named humanize”

    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是givinig這個錯誤

我也嘗試了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 )

你可以幫幫我嗎?

這就是我要怎么做。

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應該能夠自動查找和導入這些模塊。

還要確保將“ humanize”包導入到“ main.py”腳本中。

好吧,我通過完全避免setup.py進行修復。

官方文檔中還有另一種方法

打字..

cxfreeze main.py

在cmd為我工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM