3

I downloaded gspread the other day using pip. I manage to import it into a python file and run the file when using python 2.7.6 but when using python 3.4.3 it returns error no module named gspread. I did see that when I go to where gspread is installed its under 2.7.6 meanwhile I have discord api under 3.4.3. Anything I can do to get gspread to work with python3? Thank you!

I dont have problem with importing anymore but when running very simple code I get an error:

    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'

My code is only:

    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)
Martin Björn
  • 51
  • 1
  • 3

1 Answers1

1

Seems like you have used wrong version of pip. To install packages for Python3, you must use pip3. To install gspread, simply use pip3 install gspread.

In case you are missing pip3, you can install it using this command:

sudo apt-get update && sudo apt-get install python3-pip
Luke
  • 744
  • 2
  • 7
  • 23
  • @ifconfig I'd imagine he does. Majority of the time, where's Python there's pip. – Luke Aug 15 '17 at 23:35
  • Not all of the time. Some debian images I have seen come with just python, and not pip. – ifconfig Aug 15 '17 at 23:36
  • I added more information in my question, the import is now solved but when running on 3.4.3 I get an error as shown above which I dont get on 2.7.6 – Martin Björn Aug 15 '17 at 23:42