python-cx_Freeze ImportError

时间:2018-11-28 21:49:04

标签: python python-3.x python-imaging-library importerror cx-freeze

我正在使用cx_Freeze将游戏转换为可执行文件,并且始终出现此错误:

Traceback (most recent call last):
  File "setup.py", line 15, in <module>
    executables=[Executable('racecar.py')])
  File "C:\Users\Shaunak.Warty22\AppData\Local\Programs\Python\Python3732\lib\site-packages\cx_Freeze\dist.py", line 349, in setup
    distutils.core.setup(**attrs)
  File "C:\Users\Shaunak.Warty22\AppData\Local\Programs\Python\Python37-32\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Users\Shaunak.Warty22\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "C:\Users\Shaunak.Warty22\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\Shaunak.Warty22\AppData\Local\Programs\Python\Python37-32\lib\distutils\command\build.py", line 135, in run
    self.run_command(cmd_name)
  File "C:\Users\Shaunak.Warty22\AppData\Local\Programs\Python\Python37-32\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Users\Shaunak.Warty22\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\Shaunak.Warty22\AppData\Local\Programs\Python\Python37-32\lib\site-packages\cx_Freeze\dist.py", line 219, in run
    freezer.Freeze()
  File "C:\Users\Shaunak.Warty22\AppData\Local\Programs\Python\Python37-32\lib\site-packages\cx_Freeze\freezer.py", line 624, in Freeze
    self.finder = self._GetModuleFinder()
  File "C:\Users\Shaunak.Warty22\AppData\Local\Programs\Python\Python37-32\lib\site-packages\cx_Freeze\freezer.py", line 347, in _GetModuleFinder
    finder.IncludePackage(name)
  File "C:\Users\Shaunak.Warty22\AppData\Local\Programs\Python\Python37-32\lib\site-packages\cx_Freeze\finder.py", line 659, in IncludePackage
    module = self._ImportModule(name, deferredImports)
  File "C:\Users\Shaunak.Warty22\AppData\Local\Programs\Python\Python37-32\lib\site-packages\cx_Freeze\finder.py", line 351, in _ImportModule
    raise ImportError("No module named %r" % name)
ImportError: No module named 'Pillow'

这是我的setup.py:

from cx_Freeze import setup, Executable
import os

os.environ['TCL_LIBRARY'] = r'C:\Users\Shaunak.Warty22\AppData\Local\Programs\Python\Python37-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\Shaunak.Warty22\AppData\Local\Programs\Python\Python37-32\tcl\tk8.6'

options = {'packages':['pygame', 'Pillow'],
       'include_files':['Lobster-Regular.ttf', 'NosiferCaps-Regular.ttf', 'racecar.png']}

setup(
    name = 'Racecar Dodge',
    version = 0.1,
    description = 'Use your racecar to dodge obstacles and try to get as many blocks dodged as possible!',
    options={'build_exe': options},
    executables=[Executable('racecar.py')])

我在计算机上安装了Pillow,并且在setup.py中安装了Pillow,所以我对为什么出现错误感到困惑。

1 个答案:

答案 0 :(得分:0)

您在“选项”中将“枕头”列为软件包,导致cx_freeze尝试导入“枕头”-但是,应改为“ PIL”,因为这是模块的名称。 “枕头”只是包裹的人名。

<table *ngIf="resData.length > 0" mat-table class="mat-elevation-z8 table-content" [dataSource]="resData"> <ng-container *ngFor="let currentCol of keys; let colIndex = index" matColumnDef="{{ currentCol }}"> <th mat-header-cell *matHeaderCellDef>{{ currentCol }}</th> <td mat-cell *matCellDef="let element; let rowIndex = index">{{ element[colIndex] }}</td> </ng-container> <tr mat-header-row *matHeaderRowDef="keys"></tr> <tr mat-row *matRowDef="let row; columns: keys;"></tr> </table>