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

Hed*_*dgy 4 python pyinstaller google-api-python-client

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

运行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: 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:
Run Code Online (Sandbox Code Playgroud)

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

任何帮助将不胜感激!

小智 6

我能够在这里找到解决方案链接

将您的 google-api-python-client 版本更新为链接中指定的版本(对我有用)

还做了一个小 .bat 文件:

pyinstaller --hidden-import="pkg_resources.py2_warn" --hidden-import="googleapiclient" --hidden-import="apiclient"  main.py --onefile
Run Code Online (Sandbox Code Playgroud)

另请注意:我在虚拟环境中运行了 bat 文件。

  • 我可以确认这个灵魂有效!我降级了 google-api-python-client,如下所示: pip install google-api-python-client==1.8.0 (2认同)

joe*_*ion 5

实际上只是在 Windows 上遇到了这个问题,而 macOS 没问题。我正在使用fbsPyQt5 进行构建

问题

google-api-python-client不是python模块,而是资源,这意味着您不能将其作为隐藏导入注入。googleapiclient.modelgoogle-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
Run Code Online (Sandbox Code Playgroud)


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

  1. 找到 google_api_python_client-*/
    • 可能在某处 <pythonInstallLocation>/lib/site-packages/
  2. 复制google_api_python_client-*/到应用程序的 src 资源目录中。为此fbs可以是:
    • src/freeze/windows/ (推荐),或
    • src/resources/windows/

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

参见:fbs 项目目录结构

解决方案 2 - 没有自动包装挂钩(未经测试):

如果您的包装解决方案没有与上述类似的挂钩,则:

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