前几天我用pip下载了gspread。我设法将它导入到python文件中,并在使用python 2.7.6时运行该文件,但在使用python 3.4.3时,它返回错误,不返回名为gspread的模块。我确实看到,当我去安装go的地方时,它的下2.7.6,同时,我在3.4.3下有不和谐的api。我能做些什么让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)
发布于 2017-08-15 23:25:16
好像你用错了pip的版本。要安装Python3软件包,必须使用pip3
。要安装扩展,只需使用pip3 install gspread
。
如果您缺少pip3,可以使用以下命令安装它:
sudo apt-get update && sudo apt-get install python3-pip
https://stackoverflow.com/questions/45702910
复制相似问题