问题
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 application
and I'm completely lost why.
Running pip show google-api-python-client
results with
Name: google-api-python-client
Version: 1.8.2
Summary: Google API Client Library for Python
Home-page: http://github.com/google/google-api-python-client/
Author: Google LLC
Author-email: googleapis-packages@google.com
License: Apache 2.0
Location: c:\dev\software\schoology_scrape\schoology_scrape_venv\lib\site-packages
Requires: google-auth-httplib2, uritemplate, google-auth, google-api-core, httplib2, six
Required-by:
I also have a requirements.txt file with all the libraries used in the project
Any help would be greatly appreciated!
回答1:
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 <module>
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", 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 <module>
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
- Locate the
google_api_python_client-*/
- likely somewhere
<pythonInstallLocation>/lib/site-packages/
- likely somewhere
- Copy
google_api_python_client-*/
into your application's src resource directory. Forfbs
this can be either:src/freeze/windows/
(recommended), orsrc/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:
- Build your app
- Manually copy the
google_api_python_client-*/
folder from<pythonInstallLocation>/lib/site-packages/
into the built app's directory (or wherever your compiled python scripts are trying to accessgoogle-api-python-client
. - Try starting the app
pythonfbsfreezegoogle-api-python-client
回答2:
make sure that pip is linked to pip3 (Python 3) and not pip2 (Python2). On many OS(es) and distros, that's still the case.
Check if that solves your problem:
python3 -m pip install --upgrade google-api-python-client
If it did then add an alias to your .bashrc that links pip to pip3 and not pip2.
e.g.
echo "alias pip='pip3'" >> ~/.bashrc
来源:https://stackoverflow.com/questions/61510900/the-google-api-python-client-distribution-was-not-found-and-is-required-by-the