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:
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:
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.
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
Example:
service = discovery.build(api_name, api_version, credentials=credentials, static_discovery=False)
then run pyinstaller:
pyinstaller --onefile -w --icon=icon.ico --add-data client_secrets.json;. main.py --collect-data google-api-python-client --collect-data oauth2client;.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.