Import errors when trying to use pandas_gbq - python-3.x

I have been trying to run the code on this page which describes how to authenticate before using the pandas_gbq.read_gbq function:
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,)
I am getting the following error:
---------------------------------------------------------------------------
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)
I have tried uninstalling and reinstalling using the following command line code without any luck:
pip install pandas-gbq -U
This same code seems to work without any issue on my PC with Anaconda installed. However, the code does not run on my mac. Both computers have python 3.7 installed. I installed python 3 on my mac via homebrew, and I do not have Anaconda installed on that computer.

I'm facing the same problem. but solve it by installing using conda:
conda install pandas-gbq --channel conda-forge

Related

How to resolve this error when trying to use Pandas Styling?

I am running Python 3.6.5 and Pandas 0.25.2.
On attempting to style a pandas dataframe I am getting a specific error which can be generated by simplifying to this code:
import pandas as pd
import pandas.io.formats.style
The summary of the error generated is:
ImportError: The 'packaging._typing' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.
The full error message is:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-e9b944578fec> in <module>()
1 import pandas as pd
----> 2 import pandas.io.formats.style
~\Anaconda3\lib\site-packages\pandas\io\formats\style.py in <module>()
48
49
---> 50 class Styler:
51 """
52 Helps style a DataFrame or Series according to the data with HTML and CSS.
~\Anaconda3\lib\site-packages\pandas\io\formats\style.py in Styler()
109 """
110
--> 111 loader = jinja2.PackageLoader("pandas", "io/formats/templates")
112 env = jinja2.Environment(loader=loader, trim_blocks=True)
113 template = env.get_template("html.tpl")
~\Anaconda3\lib\site-packages\jinja2\loaders.py in __init__(self, package_name, package_path, encoding)
220 def __init__(self, package_name, package_path='templates',
221 encoding='utf-8'):
--> 222 from pkg_resources import DefaultProvider, ResourceManager, \
223 get_provider
224 provider = get_provider(package_name)
~\Anaconda3\lib\site-packages\pkg_resources\__init__.py in <module>()
79 from pkg_resources.extern import appdirs
80 from pkg_resources.extern import packaging
---> 81 __import__('pkg_resources.extern.packaging.version')
82 __import__('pkg_resources.extern.packaging.specifiers')
83 __import__('pkg_resources.extern.packaging.requirements')
~\Anaconda3\lib\site-packages\pkg_resources\_vendor\packaging\version.py in <module>()
9
10 from ._structures import Infinity, NegativeInfinity
---> 11 from ._typing import TYPE_CHECKING
12
13 if TYPE_CHECKING: # pragma: no cover
~\Anaconda3\lib\site-packages\pkg_resources\extern\__init__.py in load_module(self, fullname)
52 "normally this is bundled with this package so if you get "
53 "this warning, consult the packager of your "
---> 54 "distribution.".format(**locals())
55 )
56
I have tried reinstalling and upgrading the pandas installation, but each time I get the same error. This is being doine through an Anaconda environment.
Has anyone seen this error before? Is there a more detailed explanation that anyone can provide in an effort to solve this issue so that I can get the pandas styling working.
Thanks!
The correct way to do this is by:
from pandas.io.formats import style
This is because style is a module of pandas.io.formats package and the correct syntax is:
from package import module

ImportError when importing brightway2

I am getting this import error when trying to import brightway:
import brightway2 as bw
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-a3ddbb8a34e8> in <module>
----> 1 import brightway2 as bw
/opt/anaconda3/envs/bw2/lib/python3.6/site-packages/brightway2/__init__.py in <module>
1 # -*- coding: utf-8 -*
----> 2 from bw2data import *
3 from bw2calc import *
4 from bw2io import *
5
/opt/anaconda3/envs/bw2/lib/python3.6/site-packages/bw2data/__init__.py in <module>
31
32 from .configuration import config
---> 33 from .project import projects
34 from .utils import set_data_dir
35 from .meta import (
/opt/anaconda3/envs/bw2/lib/python3.6/site-packages/bw2data/project.py in <module>
6 from .errors import ReadOnlyProject
7 from .filesystem import safe_filename, create_dir
----> 8 from .sqlite import PickleField, create_database
9 from .utils import python_2_unicode_compatible
10 from fasteners import InterProcessLock
/opt/anaconda3/envs/bw2/lib/python3.6/site-packages/bw2data/sqlite.py in <module>
4
5 from peewee import SqliteDatabase, BlobField, Model, TextField
----> 6 from playhouse.shortcuts import RetryOperationalError
7 import os
8 try:
ImportError: cannot import name 'RetryOperationalError'
I am using macOS system. I have tried reinstalling conda as well but I keep getting the same error, so I am not sure what is wrong. Any help or suggestions would be greatly appreciated!
Your version of bw2data is very out of date. Since 2018, i.e. version 3.3, this code has changed. Upgrade bw2data using either conda or pip, depending on how you installed it in the first place.

Trouble importing modules into ipython

On a freshly installed Windows 10 machine, I installed the newest 64bit version of anaconda. Now when I try importing modules into ipython, I get errors. Some sample errors are reproduced below.
I am new to Python and Programming, so would appreciate a bit of help. This is a brand new Lenovo laptop, so there's no scope for any Python version conflict etc. (since nothing was installed on it earlier).
In [1]: import sklearn
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-b7c74cbf5af0> in <module>
----> 1 import sklearn
C:\Software\anaconda3\lib\site-packages\sklearn\__init__.py in <module>
74 else:
75 from . import __check_build
---> 76 from .base import clone
77 from .utils._show_versions import show_versions
78
C:\Software\anaconda3\lib\site-packages\sklearn\base.py in <module>
11 import re
12
---> 13 import numpy as np
14
15 from . import __version__
C:\Software\anaconda3\lib\site-packages\numpy\__init__.py in <module>
138
139 # Allow distributors to run custom init code
--> 140 from . import _distributor_init
141
142 from . import core
C:\Software\anaconda3\lib\site-packages\numpy\_distributor_init.py in <module>
32
33 with RTLD_for_MKL():
---> 34 from . import _mklinit
35
36 del RTLD_for_MKL
ImportError: DLL load failed: The specified module could not be found.
In [2]: import matplotlib.pyplot as plt
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-a0d2faabd9e9> in <module>
----> 1 import matplotlib.pyplot as plt
C:\Software\anaconda3\lib\site-packages\matplotlib\__init__.py in <module>
136 # cbook must import matplotlib only within function
137 # definitions, so it is safe to import from it here.
--> 138 from . import cbook, rcsetup
139 from matplotlib.cbook import (
140 MatplotlibDeprecationWarning, dedent, get_label, sanitize_sequence)
C:\Software\anaconda3\lib\site-packages\matplotlib\cbook\__init__.py in <module>
29 from weakref import WeakMethod
30
---> 31 import numpy as np
32
33 import matplotlib
C:\Software\anaconda3\lib\site-packages\numpy\__init__.py in <module>
138
139 # Allow distributors to run custom init code
--> 140 from . import _distributor_init
141
142 from . import core
C:\Software\anaconda3\lib\site-packages\numpy\_distributor_init.py in <module>
32
33 with RTLD_for_MKL():
---> 34 from . import _mklinit
35
36 del RTLD_for_MKL
ImportError: DLL load failed: The specified module could not be found.
In [3]: import pystan
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-3-ca8618bb8e4a> in <module>
----> 1 import pystan
ModuleNotFoundError: No module named 'pystan'
In [4]:
After a lot of google searching, I found a few sites that touch upon some closely related issues (ex. https://github.com/stan-dev/pystan/issues/520). It so happens that one needs to add some anaconda directroties to the Windows path. I added anaconda/Library/bin, anaconda/Scripts to the path. Now everything is working as expected.

Problem in importing Autograph in Tensorflow

I have installed Tensorflow (1.13.0) using conda as follows:
conda install -c anaconda tensorflow
on my Win64 machine with python 3.6 in my conda environment. I am able to import tensorflow from my Jupyter notebook. In my project, I need to use AutoGraph. However, when I try to import autograph, then I get this error - ImportError: cannot import name 'deprecated_endpoints'
I am able to verify that autograph folder exists in my tensorflow package "..\py36\Lib\site-packages\tensorflow\python\autograph". However, the below code statement gives that Import Error.
import tensorflow.python.autograph as ag
Complete error trace:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-13-9224a57db065> in <module>
1 import tensorflow as tf
----> 2 import tensorflow.python.autograph as ag
~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\tensorflow\python\autograph\__init__.py in <module>
33
34 # TODO(mdan): Bring only the relevant symbols to the top level.
---> 35 from tensorflow.python.autograph import operators
36 from tensorflow.python.autograph import utils
37 from tensorflow.python.autograph.core.converter import ConversionOptions
~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\tensorflow\python\autograph\operators\__init__.py in <module>
38 from __future__ import print_function
39
---> 40 from tensorflow.python.autograph.operators.control_flow import for_stmt
41 from tensorflow.python.autograph.operators.control_flow import if_stmt
42 from tensorflow.python.autograph.operators.control_flow import while_stmt
~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\tensorflow\python\autograph\operators\control_flow.py in <module>
19 from __future__ import print_function
20
---> 21 from tensorflow.python.autograph.operators import py_builtins
22 from tensorflow.python.data.ops import dataset_ops
23 from tensorflow.python.framework import tensor_util
~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\tensorflow\python\autograph\operators\py_builtins.py in <module>
24 import six
25
---> 26 from tensorflow.python.autograph.utils import py_func
27 from tensorflow.python.autograph.utils import tensors
28 from tensorflow.python.framework import constant_op
~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\tensorflow\python\autograph\utils\__init__.py in <module>
22 from tensorflow.python.autograph.utils.misc import alias_tensors
23 from tensorflow.python.autograph.utils.py_func import wrap_py_func
---> 24 from tensorflow.python.autograph.utils.tensor_list import dynamic_list_append
25 from tensorflow.python.autograph.utils.testing import fake_tf
26 from tensorflow.python.autograph.utils.type_check import is_tensor
~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\tensorflow\python\autograph\utils\tensor_list.py in <module>
20
21 from tensorflow.python.framework import ops
---> 22 from tensorflow.python.ops import list_ops
23 from tensorflow.python.ops import tensor_array_ops
24
~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\tensorflow\python\ops\list_ops.py in <module>
24 from tensorflow.python.framework import tensor_shape
25 from tensorflow.python.ops import array_ops
---> 26 from tensorflow.python.ops import gen_list_ops
27 # go/tf-wildcard-import
28 # pylint: disable=wildcard-import
~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\tensorflow\python\ops\gen_list_ops.py in <module>
21 from tensorflow.python.framework import ops as _ops
22 from tensorflow.python.framework import op_def_library as _op_def_library
---> 23 from tensorflow.python.util.deprecation import deprecated_endpoints
24 from tensorflow.python.util import dispatch as _dispatch
25 from tensorflow.python.util.tf_export import tf_export
ImportError: cannot import name 'deprecated_endpoints'
---------------------------------------------------------------------------
How should I fix it?

why import sklearn is not working in Jupyter?

I installed the recent version of Anaconda but "Import sklearn" gives an error
ImportError Traceback (most recent call last)
<ipython-input-5-b7c74cbf5af0> in <module>
----> 1 import sklearn
~\anaconda3\lib\site-packages\sklearn\__init__.py in <module>
62 else:
63 from . import __check_build
---> 64 from .base import clone
65 from .utils._show_versions import show_versions
66
~\anaconda3\lib\site-packages\sklearn\base.py in <module>
11 from scipy import sparse
12 from .externals import six
---> 13 from .utils.fixes import signature
14 from . import __version__
15
~\anaconda3\lib\site-packages\sklearn\utils\__init__.py in <module>
14 from . import _joblib
15 from ..exceptions import DataConversionWarning
---> 16 from .fixes import _Sequence as Sequence
17 from .deprecation import deprecated
18 from .validation import (as_float_array,
~\anaconda3\lib\site-packages\sklearn\utils\fixes.py in <module>
90 from ._scipy_sparse_lsqr_backport import lsqr as sparse_lsqr
91 else:
---> 92 from scipy.sparse.linalg import lsqr as sparse_lsqr # noqa
93
94
~\anaconda3\lib\site-packages\scipy\sparse\linalg\__init__.py in <module>
115 from .dsolve import *
116 from .interface import *
--> 117 from .eigen import *
118 from .matfuncs import *
119 from ._onenormest import *
~\anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\__init__.py in <module>
9 from __future__ import division, print_function, absolute_import
10
---> 11 from .arpack import *
12 from .lobpcg import *
13
~\anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\arpack\__init__.py in <module>
20 from __future__ import division, print_function, absolute_import
21
---> 22 from .arpack import *
~\anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\arpack\arpack.py in <module>
43 __all__ = ['eigs', 'eigsh', 'svds', 'ArpackError', 'ArpackNoConvergence']
44
---> 45 from . import _arpack
46 import numpy as np
47 import warnings
ImportError: DLL load failed: The specified procedure could not be found.
I found out what the problem was. I had created an env file for Jupyter and edited it to open jupyter in Chrome. After updating python, import sklearn did not work. So I had to go back and delete that env file and everything worked fine after that. Hope this helps future readers of this post.

Resources