小编Nie*_*ums的帖子

导入错误:没有名为 gspread 的模块

我正在尝试使用gspreadpython 中的库。我安装了lib,pip install gspread但是当我运行代码时:

import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://sreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('FILE_NAME.json', scope)
gc = gspread.authorize(credentials)
wks = gc.open('Changelog').sheet1
print(wks.get_all_records())
Run Code Online (Sandbox Code Playgroud)

它给了我一个错误:

File "stuff.py", line 1, in <module>
    import gspread
ImportError: No module named gspread
Run Code Online (Sandbox Code Playgroud)

当我在 python3 中运行它时,它没有给我任何导入错误。但那些:

File "stuff.py", line 8, in <module>
    gc = gspread.authorize(credentials)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/gspread/__init__.py", line 38, in authorize
    client.login()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/gspread/client.py", line 51, in login
    self.auth.refresh(http)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/oauth2client/client.py", line 545, in refresh
    self._refresh(http)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/oauth2client/client.py", line 749, …
Run Code Online (Sandbox Code Playgroud)

python python-2.7 python-3.x oauth2client gspread

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

gspread ×1

oauth2client ×1

python ×1

python-2.7 ×1

python-3.x ×1