[英]PyInstaller collect package issue (Google Analytics)?
I have the below imports:我有以下进口商品:
from apiclient import discovery
from oauth2client.service_account import ServiceAccountCredentials
I'm trying to make a single file exe file by running:我正在尝试通过运行来制作单个文件的 exe 文件:
pyinstaller --onefile -w --icon=icon.ico --add-data client_secrets.json;. main.py --collect-data "google-api-python-client" --collect-data "oauth2client";.
I also tried:我也试过:
pyinstaller --onefile -w --icon=icon.ico --add-data client_secrets.json;. main.py --collect-data google-api-python-client --collect-data oauth2client;.
But when i run the exe file I get the error:但是当我运行exe文件时出现错误:
Failed to execute script 'main' due to unhandled exception: name analytics version: v3
File "main.py", line 81, in <module>
File "main.py", line 32, in get_service
File "googleapiclient\_helpers.py", line 130, in positional_wrapper
File "googleapiclient\discovery.py", line 287, in build
File "googleapiclient\discovery.py", line 404, in _retrieve_discovery_doc
googleapiclient.errors.UnknownApiNameOrVersion: name: analytics version: v3
The script works fine as a python file.该脚本作为 python 文件工作正常。
How to reproduce:如何重现:
from apiclient import discovery
from oauth2client.service_account import ServiceAccountCredentials
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
def get_service(api_name, api_version, scopes, key_file_location):
credentials = ServiceAccountCredentials.from_json_keyfile_name(
key_file_location, scopes=scopes)
# Build the service object.
# service = build(api_name, api_version, credentials=credentials)
service = discovery.build(api_name, api_version, credentials=credentials)
return service
if __name__ == '__main__':
scope = 'https://www.googleapis.com/auth/analytics.edit'
# client_secret from console.cloud.google.com
key_file_location = f'{dir_path}/client_secrets.json'
# Authenticate and construct service.
service = get_service(
api_name='analytics',
api_version='v3',
scopes=[scope],
key_file_location=key_file_location)
The solution is to add static_discovery=False
to discovery.build解决方案是在 discovery.build 中添加static_discovery=False
Example:例子:
service = discovery.build(api_name, api_version, credentials=credentials, static_discovery=False)
then run pyinstaller:然后运行pyinstaller:
pyinstaller --onefile -w --icon=icon.ico --add-data client_secrets.json;. main.py --collect-data google-api-python-client --collect-data oauth2client;.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.