[英]PyInstaller collect package issue (Google Analytics)?
我有以下進口商品:
from apiclient import discovery
from oauth2client.service_account import ServiceAccountCredentials
我正在嘗試通過運行來制作單個文件的 exe 文件:
pyinstaller --onefile -w --icon=icon.ico --add-data client_secrets.json;. main.py --collect-data "google-api-python-client" --collect-data "oauth2client";.
我也試過:
pyinstaller --onefile -w --icon=icon.ico --add-data client_secrets.json;. main.py --collect-data google-api-python-client --collect-data oauth2client;.
但是當我運行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
該腳本作為 python 文件工作正常。
如何重現:
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)
解決方案是在 discovery.build 中添加static_discovery=False
例子:
service = discovery.build(api_name, api_version, credentials=credentials, static_discovery=False)
然后運行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.