python - 如何解决 pyinstaller exe 中的“pkg_resources.DistributionNotFound”错误
问题描述
我正在尝试制作一个使用 Google Drive API 的应用程序。我正在使用 PyInstaller 将我的 python 文件转换为可执行文件。我运行了从最基本的 python 脚本生成的 .exe 文件,我得到了一个错误,上面写着
pkg_resources.DistributionNotFound: The 'google-api-python-client' distribution was not found and is required by the application
我的代码甚至没有使用“google-api-python-client”,但我将它安装在我的 anaconda 环境中,但我仍然面临同样的问题。
我正在添加代码以供参考:-
import pickle
import os
from googleapiclient.discovery import build
from google.auth.transport.requests import Request
def Create_Service(client_secret_file, api_name, api_version, *scopes):
print(client_secret_file, api_name, api_version, scopes, sep='-')
CLIENT_SECRET_FILE = client_secret_file
API_SERVICE_NAME = api_name
API_VERSION = api_version
SCOPES = [scope for scope in scopes[0]]
print(SCOPES)
cred = None
pickle_file = f'token_{API_SERVICE_NAME}_{API_VERSION}.pickle'
print(pickle_file)
if os.path.exists(pickle_file):
with open(pickle_file, 'rb') as token:
cred = pickle.load(token)
if not cred or not cred.valid:
if cred and cred.expired and cred.refresh_token:
cred.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRET_FILE, SCOPES)
cred = flow.run_local_server(port=0)
with open(pickle_file, 'wb') as token:
pickle.dump(cred, token)
try:
service = build(API_SERVICE_NAME, API_VERSION, credentials=cred)
print(API_SERVICE_NAME, 'service created successfully')
return service
except Exception as e:
print('Unable to connect.')
print(e)
return None
s=Create_Service('client_secret_kc.json','drive','v3',['https://www.googleapis.com/auth/drive'])
我用来转换成.exe的pyinstaller代码如下
pyinstaller -c -F --add-data "client_secret_kc.json;." Google.py
NB- Google.py 是上面的 python 脚本 gien 的名称。
感谢您的帮助。
解决方案
推荐阅读
- reactjs - 使用 react 实现客户端过滤
- reactjs - 在 React 中循环两个数组以返回表
- react-native - 通过路由 props 从 Child 到 Parent 共享状态
- android - Flutter image_picker 权限找不到有效的活动来处理请求
- c# - 如何使用 IServiceScopeFactory.CreateScope
- ios - 当我们在iOS13中将设备设置为横向模式时,UITabBarItem标题文本未居中对齐
- python - Pandas:有条件地组合多索引数据帧
- core-data - SwiftUI:屏幕锁定后列表没有核心数据对象,空视图
- sql-server - 我们如何在 MSSQL 查询中聚合字符串数据类型
- python - 什么可能导致python关闭而没有任何错误?