I have written a Kivy application and I am now trying to use PyInstaller to package it for MacOS. It uses the Google Calendar API so I need to use the google-api-python-client module. When I packaged the application according to the Kivy packaging instructions, the google-api-python-client was not found. I got this error:
[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
This is my spec file:
# -*- 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")
I have looked at this post, but the answer did not work with PyInstaller. Thanks for any help!
The answer was to copy a folder from site-packages
called google_api_python_client-x.y.z.dist-info
. This folder was supposed to be copied into the *.app/Contents/MacOS/
. But then I found the proper way to do this was put this tuple into the datas=[*]
line in the *.spec file: ('/path/to/lib/site-packages/google_api_python_client-x.y.z.dist-info/*', 'google_api_python_client-x.y.z.dist-info')
.