PyInstaller file fails to execute script - DistributionNotFound

后端 未结 5 1529
庸人自扰
庸人自扰 2020-12-10 18:22

I\'m trying to convert my python file to an executable using PyInstaller. The program uses the Google Cloud Translate API to translate given text between languages. When run

相关标签:
5条回答
  • 2020-12-10 18:49

    It is basically package building name issue. Pyinstaller tries to import

    google.cloud

    where Google cloud package is now called

    gcloud

    . So you need to create a hook file for that names

    C:\Users\\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\PyInstaller\hooks\hook-gcloud.py

    File contents:

    from PyInstaller.utils.hooks import copy_metadata
    
    datas = copy_metadata('gcloud')
    
    0 讨论(0)
  • 2020-12-10 18:53

    I had the exact same issue. I solved it by doing this:

    1. Goto the Pyinstaller hooks folder (~\Lib\site-packages\PyInstaller\hooks)
    2. Find the file hook-google.cloud.py, open it, and add the following code to it
    datas += copy_metadata('google-cloud-translate')
    datas += copy_metadata('google-api-core')
    

    The issue seems to be that get_distribution is not working with the default google.cloud.translate hook, so I just added this to a hook that was working.

    Hope this helps someone.

    0 讨论(0)
  • 2020-12-10 19:03

    In my experience base on the helps in https://github.com/GoogleCloudPlatform/google-cloud-python/issues/1187 :

    1. Go \Anaconda3\Lib\site-packages\PyInstaller\hooks folder (if you use anaconda otherwise you need to find it under python folder)
    2. Find the hook-google-cloud.py (If exist, otherwise you need to creat the hook.
    3. Write to existing code as shown below


      Copyright (c) 2017, PyInstaller Development Team.

      Distributed under the terms of the GNU General Public License with exception for distributing bootloader.

      The full license is in the file COPYING.txt, distributed with this software.


      from PyInstaller.utils.hooks import copy_metadata

      datas = copy_metadata('google-cloud-core')

      datas += copy_metadata('google-cloud-translate')

      datas += copy_metadata('google-api-core')


      Hope you find this explaination helpful. Thank you.

    0 讨论(0)
  • 2020-12-10 19:05

    Alternate hook tweak

    I'm running into this same essential problem with the Google speech engine.

    It's odd how everyone here seems to have success with slightly alternate solutions to this. I really don't understand how the "patches" to the hook which leave copy_metadata('google-cloud-core') in place can work? The error thrown back reads The 'google-cloud-core' distribution was not found..., so how can one execute that line as is?

    This is my replacement for the file content of hook-google.cloud.py, in order to build an exe using google speech:

    # PATCH: PROVIDED ALTERNATE PACKAGE NAME
    from PyInstaller.utils.hooks import copy_metadata
    try:    datas = copy_metadata('google-cloud-core')
    except: datas = copy_metadata('google-cloud-speech')
    
    0 讨论(0)
  • 2020-12-10 19:11

    My personal solution:

    1. Change all calls to get_distribution with it returned values (0.21.0 in my case)
    2. Remove from pkg_resources import get_distribution from import

    for all files in the package.

    0 讨论(0)
提交回复
热议问题