Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
861 views
in Technique[技术] by (71.8m points)

python - PyInstaller file fails to execute script - DistributionNotFound

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 running python quicktrans.py in the terminal, the program works fine. Then I ran pyinstaller quicktrans.py, SHIFT + right-clicked the directory the executable was in, and ran the .exe file in the terminal. This is the traceback that it spit out (Note this is not the whole traceback because it is a little lengthy):

File "c:userskalab
ealpythonquicktransgooglecloudconnection.py", line 31, in <module>
    get_distribution('google-cloud-core').version)
  File "site-packagespkg_resources\__init__.py", line 559, in get_distribution
  File "site-packagespkg_resources\__init__.py", line 433, in get_provider
  File "site-packagespkg_resources\__init__.py", line 970, in require
  File "site-packagespkg_resources\__init__.py", line 856, in resolve
pkg_resources.DistributionNotFound: The 'google-cloud-core' distribution was not found and is required by the application
Failed to execute script quicktrans

I've tried looking into this and some reason it's giving me a pip-like error. I've been trying to fix this for hours and no luck. Note: To install its client library, as per the documentation, you must run pip install --upgrade google-cloud-translate

I'm thinking this might have something to do with this because the last application I used dealt with the Facebook client module and you only had to do pip install facebook-sdk and the executable made by PyInstaller ran with no issues.

If you want to examine my code used in my program, it's hosted on my GitHub.

Thanks to anyone helping me out here!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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\AppDataLocalProgramsPythonPython36-32Libsite-packagesPyInstallerhookshook-gcloud.py

File contents:

from PyInstaller.utils.hooks import copy_metadata

datas = copy_metadata('gcloud')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...