2

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!

Nv7
  • 406
  • 6
  • 20
  • Hi @Nv7, what about the post you linked did not work? I have had the same issue with google-api-python-client and was able to solve it by copying the site package into the dist folder from pyinstaller. – Dr. Mantis Tobbogan Jun 26 '20 at 19:04
  • I do not think there is a src folder in PyInstaller projects. Where did you copy google-api-python-client? My dist folder just has a *.app folder – Nv7 Jun 26 '20 at 20:51
  • You are right, there is not a source folder for distribution package created by pyinstaller. What you need to try (and isn't exactly explicit in the other post) is to copy the google-api-python-client folder from where your main Python environment is setup and copy it into the root folder of your app. For example if my Python environment is located at /user/venv/kivy_google_app, I would search the folder for the google-api-python-client-xxxversionxxx and paste it straight into the root of the build folder created by pyinstaller (*.app using your example). – Dr. Mantis Tobbogan Jun 27 '20 at 21:19
  • By the root folder do you mean the *.app/ or the *.app/Contents or the *.app/Contents/MacOS *.app/Contents/Resources folder? – Nv7 Jun 28 '20 at 22:49
  • I mean the *.app folder – Dr. Mantis Tobbogan Jun 29 '20 at 17:13
  • There were a couple things wrong - I'll make an answer. I was copying the wrong thing. – Nv7 Jun 30 '20 at 18:32

2 Answers2

0

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').

Nv7
  • 406
  • 6
  • 20
0

Another answer which could solve your problem in one line, hopefully, could be adding the folder with --add-data argument. Relevant link and also this.

pyinstaller [.py_name] -n [.exe_name] --onefile --add-data [SRC:DEST]

In your case --add-data '/path/to/lib/site-packages/google_api_python_client-x.y.z.dist-info:google_api_python_client-x.y.z.dist-info'

Couple of issues I had before:

  • Couldn't make it work for SRC part to write it in absolute path form, it should be a relative path.

  • Path takes it from the current working folder. For one of my earlier builds, I needed to go back couple of folders with ../../, so if the file you want to add is not in the current working folder, you can do it that way.

  • Quotation marks for the paths, for quite some time I didn't need to use them, in fact, they resulted in an error. But in this last month, due to some update on pyinstaller I guess, I needed to add quotation marks again.

  • Between SRC and DEST it could be ';' or ':', I am using ';' for Windows, so maybe ':' for the macOS.

The question you linked has a different answer which linked a GitHub page with details here where I also shared my findings before that more or less boils down to the above-mentioned method and explanation.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Acibiber53
  • 51
  • 5