前几天我用pip下载了gspread。我设法将它导入到一个python文件中,并在使用python 2.7.6时运行该文件,但在使用python 3.4.3时,它不会返回名为gspread的模块错误。当我转到gspread在2.7.6下的安装位置时,我确实看到了这一点,同时我在3.4.3下有discord api。我能做些什么让葛斯派德和蟒蛇一起工作吗?谢谢您!
我不再有导入的问题,但是当运行非常简单的代码时,我会得到一个错误:

    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

10-07 15:11