未找到“google-api-python-client”发行版,并且 pyinstaller 的应用程序需要该发行版

2024-03-29

我目前正在尝试使用 pyinstaller 构建一个应用程序。我收到了错误The 'google-api-python-client' distribution was not found and is required by the application我完全不明白为什么。

Running pip show google-api-python-client结果与

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: [email protected] /cdn-cgi/l/email-protection
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:

我还有一个requirements.txt 文件,其中包含项目中使用的所有库

任何帮助将不胜感激!


从字面上看,只是在 Windows 上遇到了这个问题,而 macOS 没问题。我正在建设fbs https://build-system.fman.io/manual/ and PyQt5 https://pypi.org/project/PyQt5/.

问题

google-api-python-client不是一个Python模块,而是一个资源,这意味着你不能将它作为隐藏导入注入。googleapiclient.model从中读取分布信息google-api-python-client文件夹作为打包资源。

您的完整错误可能看起来更接近此:

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

解决方案 1 – 如果使用 fbs 或其他常见的打包框架

  1. Locate the google_api_python_client-*/
    • 可能在某个地方<pythonInstallLocation>/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/(推荐),或
    • src/resources/windows/

现在当你fbs freeze随后fbs installer您的应用程序,google_api_python_client-*/将与其他应用程序一起包含在构建的应用程序的目录中googleapiclientpython 库,错误应该消失。

参见:fbs项目目录结构 https://i.stack.imgur.com/agIHc.png

解决方案 2 - 无自动打包钩子(未经测试):

如果您的包装解决方案没有与上面类似的钩子,那么:

  1. 构建您的应用程序
  2. 手动复制google_api_python_client-*/文件夹来自<pythonInstallLocation>/lib/site-packages/进入构建的应用程序的目录(或者你编译的Python脚本试图访问的任何地方)google-api-python-client.
  3. 尝试启动应用程序

python /questions/tagged/pythonfbs /questions/tagged/fbsfreeze /questions/tagged/freeze谷歌 API python 客户端 /questions/tagged/google-api-python-client

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

未找到“google-api-python-client”发行版,并且 pyinstaller 的应用程序需要该发行版 的相关文章

随机推荐