gpt4 book ai didi

python - 使用 python 3.4.3 时无法导入 gspread

转载 作者:行者123 更新时间:2023-11-28 18:19:57 25 4
gpt4 key购买 nike

前几天我使用 pip 下载了 gspread。我设法将其导入 python 文件并在使用 python 2.7.6 时运行该文件,但在使用 python 3.4.3 时返回错误 no module named gspread。我确实看到,当我去安装 gspread 的地方时,它在 2.7.6 下,同时我在 3.4.3 下有 discord api。我可以做些什么来让 gspread 与 python3 一起工作?谢谢!

我在导入时没有问题,但是当运行非常简单的代码时,我得到一个错误:

    Traceback (most recent call last):
File "test.py", line 11, in <module>
sheet = client.open('Test').sheet1
File "/home/marbj634/.local/lib/python3.4/site-packages/gspread/client.py", line 82, in open
feed = self.get_spreadsheets_feed()
File "/home/marbj634/.local/lib/python3.4/site-packages/gspread/client.py", line 155, in get_spreadsheets_feed
r = self.session.get(url)
File "/home/marbj634/.local/lib/python3.4/site-packages/gspread/httpsession.py", line 73, in get
return self.request('GET', url, params=params, **kwargs)
File "/home/marbj634/.local/lib/python3.4/site-packages/gspread/httpsession.py", line 65, in request
response = func(url, data=data, params=params, headers=request_headers, files=files, json=json)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 467, in get
return self.request('GET', url, **kwargs)
TypeError: request() got an unexpected keyword argument 'json'

我的代码只有:

    import gspread
from oauth2client.service_account import ServiceAccountCredentials
import pprint

scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.authorize(creds)

pp = pprint.PrettyPrinter()

sheet = client.open('Test').sheet1

values = sheet.get_all_values()

pp.pprint(values)

最佳答案

似乎您使用了错误版本的 pip。要为 Python3 安装包,您必须使用 pip3。要安装 gspread,只需使用 pip3 install gspread

如果你缺少 pip3,你可以使用这个命令安装它:

sudo apt-get update && sudo apt-get install python3-pip

关于python - 使用 python 3.4.3 时无法导入 gspread,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45702910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com