簡體   English   中英

使用python 3.4.3時無法導入gspread

[英]Cant import gspread when using python 3.4.3

我前幾天用pip下載了gspread。 我設法將它導入python文件並在使用python 2.7.6時運行該文件但是當使用python 3.4.3時它返回錯誤沒有名為gspread的模塊 我確實看到當我去gspread安裝在2.7.6以下的同時我在3.4.3下有disord 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM