【发布时间】:2020-10-13 17:44:54
【问题描述】:
我已经编写了一个 Kivy 应用程序,现在我正在尝试使用 PyInstaller 为 MacOS 打包它。它使用 Google Calendar API,所以我需要使用 google-api-python-client 模块。当我按照 Kivy 打包说明打包应用时,没有找到 google-api-python-client。我收到了这个错误:
[INFO ] [Logger ] Record log in /_____/.kivy/logs/kivy_20-06-23_6.txt
[INFO ] [Kivy ] v1.11.1
[INFO ] [Kivy ] Installed at "/____.app/Contents/MacOS/kivy/__init__.pyc"
[INFO ] [Python ] v3.7.4 (v3.7.4:e09359112e, Jul 8 2019, 14:54:52)
[Clang 6.0 (clang-600.0.57)]
[INFO ] [Python ] Interpreter at "/____/Contents/MacOS/___"
[INFO ] [Factory ] 184 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_imageio, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] Using the "OpenGL ES 2" graphics system
[INFO ] [GL ] Backend used <sdl2>
[INFO ] [GL ] OpenGL version <b'2.1 INTEL-14.5.22'>
[INFO ] [GL ] OpenGL vendor <b'Intel Inc.'>
[INFO ] [GL ] OpenGL renderer <b'Intel Iris Pro OpenGL Engine'>
[INFO ] [GL ] OpenGL parsed version: 2, 1
[INFO ] [GL ] Shading version <b'1.20'>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <16>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
Traceback (most recent call last):
File "main.py", line 11, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "/the_venv_directory/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "googleapiclient/discovery.py", line 67, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "/the_venv_directory/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "googleapiclient/http.py", line 67, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "/the_venv_directory/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "googleapiclient/model.py", line 36, in <module>
File "pkg_resources/__init__.py", line 481, in get_distribution
File "pkg_resources/__init__.py", line 357, in get_provider
File "pkg_resources/__init__.py", line 900, in require
File "pkg_resources/__init__.py", line 786, in resolve
pkg_resources.DistributionNotFound: The 'google-api-python-client' distribution was not found and is required by the application
[64310] Failed to execute script main
logout
这是我的规范文件:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['main.py'],
pathex=['Project Parent Directory'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=['_tkinter', 'Tkinter', 'enchant', 'twisted'],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='___',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=False , icon='Icon.icns')
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='___')
app = BUNDLE(coll,
name='___.app',
icon='Icon.icns',
bundle_identifier="com.___.talkingcalendar")
我查看了this 的帖子,但答案不适用于 PyInstaller。感谢您的帮助!
【问题讨论】:
-
嗨@Nv7,你链接的帖子没有工作怎么办?我在使用 google-api-python-client 时遇到了同样的问题,并且能够通过将站点包从 pyinstaller 复制到 dist 文件夹中来解决它。
-
我认为 PyInstaller 项目中没有 src 文件夹。你在哪里复制 google-api-python-client?我的 dist 文件夹只有一个 *.app 文件夹
-
你是对的,pyinstaller创建的分发包没有源文件夹。您需要尝试的(并且在另一篇文章中并未完全明确)是从设置主要 Python 环境的位置复制 google-api-python-client 文件夹并将其复制到应用程序的根文件夹中。例如,如果我的 Python 环境位于 /user/venv/kivy_google_app,我将在文件夹中搜索 google-api-python-client-xxxversionxxx 并将其直接粘贴到由 pyinstaller (*.app) 创建的构建文件夹的根目录中使用你的例子)。
-
根文件夹是指 *.app/ 或 *.app/Contents 还是 *.app/Contents/MacOS *.app/Contents/Resources 文件夹?
-
我的意思是 *.app 文件夹
标签: python-3.x kivy pyinstaller google-api-python-client