Kivy - 在 Windows 上创建包

Kivy - Create package on Windows

大家好,感谢您抽出时间来帮助我。

我目前正在尝试使用 PyInstaller (3.1) 为我的 Kivy (1.9.1) 应用创建一个 windows 包。我按照文档中的说明进行操作,但无法正常工作。因此,我尝试使用作为示例给出的演示应用程序 'touchtracer',结果相同。我收到以下错误:

Traceback (most recent call last):
  File "<string>", line 11, in <module>
  File "f:\temp\pip-build-1elcla\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
  File "C:\Python27\lib\site-packages\pkg_resources\__init__.py", line 48, in <module>
    from pkg_resources.extern import six
  File "C:\Python27\lib\site-packages\pkg_resources\extern\__init__.py", line 60, in load_module
    "distribution.".format(**locals())
ImportError: The 'six' package is required; normally this is bundled
with this package so if you get this warning, consult the packager of
your distribution.

pyi_rth_pkgres returned -1

这是我的 .spec 文件:

# -*- mode: python -*-
from kivy.deps import sdl2, glew

block_cipher = None


a = Analysis(['C:\Python27\share\kivy-examples\demo\touchtracer\main.py'],
             pathex=['C:\Users\PC\Documents\Njord\njord\Nouveau dossier'],
             binaries=None,
             datas=None,
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='touchtracer',
          debug=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe, Tree('C:\Python27\share\kivy-examples\demo\touchtracer\'),
               a.binaries,
               a.zipfiles,
               a.datas,
               *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
               strip=False,
               upx=True,
               name='touchtracer')

我已经尝试使用从 pip 安装的 Kivy 包和 wheel 的方法,但没有成功。有人有解释吗?

再次感谢。

我不得不添加这一行来解决这个问题。

         hiddenimports=['six','packaging','packaging.version','packaging.specifiers'],

我设法找到了解决问题的方法。我试图将 "six" 包添加到 hidden_imports,但后来缺少 "packaging" 包。

然后我通过简单安装安装了 setuptools 19.4,这一次,即使 "six" 在我的 hidden_imports 中,我也得到了我的第一个错误,加上一大堆警告。 我环顾四周,有人说 setuptools 19.4 有问题,应该恢复到 19.2。我做到了,然后 kivy.app 不见了,但这是进步。

我在 spec 文件的 hidden_imports 中添加了 kivy,这导致了另一个错误,指出我的一个模块存在属性错误。我只需要添加其他依赖项(sqlalchemy、sqlalchemy.orm、uuid)。

快速回顾:如果您安装了 setuptools,请确保它是 19.2。将外部依赖项添加到 hidden_imports,包括 kivy。