尝试使用pandas_gbq时出现导入错误

时间:2019-07-16 19:54:17

标签: python-3.x pandas

我一直试图在this页面上运行该代码,该页面描述了在使用pandas_gbq.read_gbq函数之前如何进行身份验证:

import pandas_gbq
import pydata_google_auth

SCOPES = [
    'https://www.googleapis.com/auth/cloud-platform',
    'https://www.googleapis.com/auth/drive',
]

credentials = pydata_google_auth.get_user_credentials(
    SCOPES,
    # Set auth_local_webserver to True to have a slightly more convienient
    # authorization flow. Note, this doesn't work if you're running from a
    # notebook on a remote sever, such as over SSH or with Google Colab.
    auth_local_webserver=True,)


df = pandas_gbq.read_gbq(
    "SELECT my_col FROM `my_dataset.my_table`",
    project_id='YOUR-PROJECT-ID',
    credentials=credentials,)

我遇到以下错误:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/usr/local/lib/python3.7/site-packages/pandas_gbq/gbq.py in _test_google_api_imports()
     94 
---> 95     try:
     96         from google.cloud import bigquery  # noqa

/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/google/cloud/bigquery/__init__.py in <module>
     34 
---> 35 from google.cloud.bigquery.client import Client
     36 from google.cloud.bigquery.dataset import AccessEntry

/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/google/cloud/bigquery/client.py in <module>
     52 from google.cloud.bigquery import _pandas_helpers
---> 53 from google.cloud.bigquery.dataset import Dataset
     54 from google.cloud.bigquery.dataset import DatasetListItem

/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/google/cloud/bigquery/dataset.py in <module>
     23 from google.cloud.bigquery import _helpers
---> 24 from google.cloud.bigquery.model import ModelReference
     25 from google.cloud.bigquery.routine import RoutineReference

/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/google/cloud/bigquery/model.py in <module>
     26 from google.cloud.bigquery import _helpers
---> 27 from google.cloud.bigquery_v2 import types
     28 

/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/google/cloud/bigquery_v2/__init__.py in <module>
     22 
---> 23 from google.cloud.bigquery_v2 import types
     24 from google.cloud.bigquery_v2.gapic import enums

/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/google/cloud/bigquery_v2/types.py in <module>
     22 
---> 23 from google.cloud.bigquery_v2.proto import model_pb2
     24 from google.cloud.bigquery_v2.proto import model_reference_pb2

/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/google/cloud/bigquery_v2/proto/model_pb2.py in <module>
     27 from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2
---> 28 from google.api import client_pb2 as google_dot_api_dot_client__pb2
     29 

ImportError: cannot import name 'client_pb2' from 'google.api' (/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/google/api/__init__.py)

我尝试使用以下命令行代码进行卸载和重新安装,但没有任何运气:

pip install pandas-gbq -U

在安装Anaconda的PC上,相同的代码似乎可以正常工作。但是,该代码无法在我的Mac上运行。两台计算机都安装了python 3.7。我通过自制软件在Mac上安装了python 3,但该计算机上没有安装Anaconda。

0 个答案:

没有答案