从字面上看,只是在 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 或其他常见的打包框架
- Locate the
google_api_python_client-*/
- 可能在某个地方
<pythonInstallLocation>/lib/site-packages/
- 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-*/
将与其他应用程序一起包含在构建的应用程序的目录中googleapiclient
python 库,错误应该消失。
参见:fbs项目目录结构 https://i.stack.imgur.com/agIHc.png
解决方案 2 - 无自动打包钩子(未经测试):
如果您的包装解决方案没有与上面类似的钩子,那么:
- 构建您的应用程序
- 手动复制
google_api_python_client-*/
文件夹来自<pythonInstallLocation>/lib/site-packages/
进入构建的应用程序的目录(或者你编译的Python脚本试图访问的任何地方)google-api-python-client
.
- 尝试启动应用程序
python /questions/tagged/pythonfbs /questions/tagged/fbsfreeze /questions/tagged/freeze谷歌 API python 客户端 /questions/tagged/google-api-python-client