尝试访问Google电子表格,但没有名为“ google”的模块

时间:2019-08-18 12:27:48

标签: python pycharm google-oauth2 service-accounts

尝试从我的一个Google电子表格中读取数据。

我从Google获得了JSON文件,试图将其作为字符串放入脚本中。

这是我到目前为止所拥有的:

import json
import os
from google.oauth2 import service_account
from google.cloud import translate
.
.
.
    json_as_string = """........"""
    info = json.loads(os.environ[json_as_string])
    creds = service_account.Credentials.from_service_account_info(info)
    # Instantiates a client
    translate_client = translate.Client(credentials=creds)
    # credentials = ServiceAccountCredentials.from_json_keyfile_name("SendMyCardCheckUP-2e671ca3c2eb.json", scope)
    client = gspread.authorize(credentials)
    sheet = client.open("file_name").sheet1

这就是我得到的:

    from google.oauth2 import service_account
ModuleNotFoundError: No module named 'google'

已经尝试通过cmd-

pip install -t lib google-auth google-auth-httplib2 google-api-python-client --upgrade

pip install --upgrade google-api-python-client

由于某些原因,导入“ google”软件包无效,有什么想法吗?

编辑:

not compiled

error

点列表:

Package                  Version
------------------------ ----------
altgraph                 0.16.1
asn1crypto               0.24.0
attrs                    19.1.0
beautifulsoup4           4.8.0
cachetools               3.1.0
certifi                  2018.11.29
cffi                     1.12.3
chardet                  3.0.4
cryptography             2.6.1
cycler                   0.10.0
decorator                4.4.0
future                   0.17.1
google                   2.0.2
google-api-core          1.14.2
google-api-python-client 1.7.11
google-auth              1.6.3
google-auth-httplib2     0.0.3
google-auth-oauthlib     0.4.0
google-cloud             0.34.0
google-cloud-core        1.0.3
google-cloud-storage     1.18.0
google-cloud-translate   1.6.0
google-oauth             1.0.1
google-resumable-media   0.3.2
googleapis-common-protos 1.6.0
grpcio                   1.23.0
gspread                  3.1.0
httplib2                 0.12.3
idna                     2.8
ipython-genutils         0.2.0
jsonschema               3.0.1
jupyter-core             4.4.0
kiwisolver               1.1.0
macholib                 1.11
matplotlib               3.0.3
nbformat                 4.4.0
numpy                    1.16.3
oauth2client             4.1.3
oauthlib                 3.0.1
opencv-python            4.1.0.25
pefile                   2018.8.8
pip                      19.2.2
plotly                   3.8.1
protobuf                 3.8.0rc1
py                       1.8.0
pyasn1                   0.4.5
pyasn1-modules           0.2.5
pycparser                2.19
pygame                   1.9.6
PyInstaller              3.4
pyOpenSSL                19.0.0
pyparsing                2.4.0
pyrsistent               0.15.1
python-dateutil          2.8.0
python-pygaze            0.6.0a25
pytz                     2019.1
pywin32-ctypes           0.2.0
requests                 2.22.0
requests-oauthlib        1.2.0
retrying                 1.3.3
rsa                      4.0
selenium                 3.141.0
setuptools               39.0.1
six                      1.12.0
soupsieve                1.9.2
traitlets                4.3.2
uritemplate              3.0.0
urllib3                  1.24.1

2 个答案:

答案 0 :(得分:1)

发现它-

pip install google_oauth2_tool

将使service account起作用。

pip install google-cloud-storage

将使from google.cloud工作

答案 1 :(得分:0)

pip install google.cloud.translate