代码在Pycharm中或在运行.py文件时运行得很好,但我需要该应用程序成为一个.exe文件,以便在没有python的设备上运行。
我正在尝试允许用户从tkinter窗口报告bug/在应用程序中提供反馈。然后,反馈通过gmail发送给我。
.exe文件是由pyinstaller (从虚拟环境中运行)生成的,当运行exe文件时,所有操作都正常,直到:
service = build(serviceName='gmail',
version='v1',
credentials=creds,
discoveryServiceUrl="https://gmail.googleapis.com/$discovery/rest?version=v1")
它产生的地方
File "googleapiclient\_helpers.py", line 134, in positional_wrapper
File "googleapiclient\discovery.py", line 273, in build
File "googleapiclient\discovery.py", line 387, in _retrieve_discovery_doc
googleapiclient.errors.UnknownApiNameOrVersion: name: gmail version: v1
当单击tkinter按钮时,将执行下面的代码。
gmail代码几乎完全复制自google示例。
小代码片段:
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
SCOPES = ['https://www.googleapis.com/auth/gmail.send']
def process_report():
creds = None
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'client_id.json', SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.json', 'w') as token:
token.write(creds.to_json())
service = build(serviceName='gmail',
version='v1',
credentials=creds,
discoveryServiceUrl="https://gmail.googleapis.com/$discovery/rest?version=v1")
msg = create_message("sender_email@gmail.com",
"reciever_email@other.com",
subject, message)
send_message(service, "me", msg)
任何帮助或建议都是非常感谢的。
发布于 2021-04-01 04:54:10
通过将google python-客户机恢复为1.8.0解决了这个问题。
pip安装google=1.8.0
发布于 2021-05-07 04:14:47
谷歌课堂api也有同样的问题。作为.py工作,在与pyinstaller转换时不作为.exe工作。完全相同的错误,除了谷歌教室api。
完全相同的解决方案起作用了(还原)。我本想发表评论的,但我没有足够的观点发表评论。
发布于 2022-05-24 16:24:18
按照这里的建议,将降级为1.8.0也对我有帮助。
以下是另一个对我也有效的解决方案,它似乎是更优雅的解决方案,因为不需要降级:
在构建函数中添加static_discovery=False解决了这个问题。
您的构建函数将类似于此构建(“驱动器”、“v3”、credentials=creds、static_discovery=False)
来源:Python: Google Drive API v3 Can't Work After Converted to .exe Using Pyinstaller
https://stackoverflow.com/questions/66700249
复制相似问题