The 'google-api-python-client' distribution was not found and is required by the application with pyinstaller

后端 未结 6 900
长情又很酷
长情又很酷 2020-12-02 01:13

I am currently trying to build an app with pyinstaller. I have gotten the error The \'google-api-python-client\' distribution was not found and is required by the appl

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 01:40

    Literally just ran into this issue on windows, whereas macOS is okay. I'm building with fbs and PyQt5.

    The Problem

    google-api-python-client is not a python module, but a resource, which means you cannot inject it as a hidden-import. googleapiclient.model reads the distribution info from google-api-python-client folder as a packaged resource.

    Your full error might look closer to this:

    ...
    File "c:\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
        exec(bytecode, module.__dict__)
      File "site-packages\googleapiclient\http.py", line 67, in 
      File "", line 971, in _find_and_load
      File "", line 955, in _find_and_load_unlocked
      File "", line 665, in _load_unlocked
      File "c:\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
        exec(bytecode, module.__dict__)
      File "site-packages\googleapiclient\model.py", line 36, in 
      File "site-packages\pkg_resources\__init__.py", line 479, in get_distribution
      File "site-packages\pkg_resources\__init__.py", line 355, in get_provider
      File "site-packages\pkg_resources\__init__.py", line 898, in require
      File "site-packages\pkg_resources\__init__.py", line 784, in resolve
    pkg_resources.DistributionNotFound: The 'google-api-python-client' distribution was not found and is required by the application
    


    Solution 1 – If using fbs or other common packaging framework

    1. Locate the google_api_python_client-*/
      • likely somewhere /lib/site-packages/
    2. Copy google_api_python_client-*/ into your application's src resource directory. For fbs this can be either:
      • src/freeze/windows/ (recommended), or
      • src/resources/windows/

    Now when you fbs freeze and subsequently fbs installer your app, the google_api_python_client-*/ will be included in the built app's directory alongside other googleapiclient python libraries, and the error should go away.

    See: fbs project directory structure

    Solution 2 - No auto-packaging hooks (untested):

    If your packaging solution does not have similar hooks as above, then:

    1. Build your app
    2. Manually copy the google_api_python_client-*/ folder from /lib/site-packages/ into the built app's directory (or wherever your compiled python scripts are trying to access google-api-python-client.
    3. Try starting the app

    pythonfbsfreezegoogle-api-python-client

提交回复
热议问题