2017-08-15 173 views
3

我有一天使用pip下載了gspread。我設法將它導入python文件並在使用python 2.7.6時運行該文件,但是在使用python 3.4.3時它會返回錯誤沒有名爲gspread的模塊。我確實看到,當我在2.7.6下安裝gspread的時候,我在3.4.3下有不合理的api。我能做些什麼來讓gspread與python3一起工作?謝謝!使用python時無法導入gspread 3.4.3

我沒有與進口了,但運行非常簡單的代碼時的問題,我得到一個錯誤:

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) 
+1

你使用PIP的正確版本:

如果你缺少PIP 3,你可以使用這個命令安裝它?有PIP和PIP3。 –

+0

是否有可能將gspread文件夾從python2.7複製到python3.4? –

+0

我用pip,python3是pip3嗎? –

回答

0

好像你已經使用PIP的版本錯誤。要安裝Python3的包,您必須使用pip3。要安裝gspread,只需使用pip3 install gspread

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

如果他還沒有獲得pip3,那麼... – ifconfig

+0

@ifconfig我想象他會這樣做。大部分時間,Python的點數在哪裏。 –

+0

不是所有的時間。我看到的一些debian圖像只是用python而不是pip。 – ifconfig