Pylint cannot find google.cloud

I installed the Google Cloud SDK and want the code I write to pass pylint. Unfortunately, anytime I import something from Google. * I get an error message:

E: 10, 0: No name 'cloud' in module 'path/to/my/current/module.google' (no-name-in-module)
E: 10, 0: Unable to import 'google.cloud' (import-error)

Versions:

$: pylint --version
pylint 1.7.0, 
astroid 1.5.0
Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4]

If I put a hook in pylint to print the sys path, I get nothing interesting. Google-cloud-sdk is in /usr/local/lib/python2.7/dist-packagesso that it can find it.

['/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/local/lib/python2.7/dist-packages/pylint-1.7.0-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/backports.functools_lru_cache-1.3-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/configparser-3.5.0-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/singledispatch-3.4.0.3-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/editdistance-0.3.1-py2.7-linux-x86_64.egg', '/usr/local/lib/python2.7/dist-packages/mccabe-0.6.1-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/astroid-1.5.0-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/wrapt-1.10.10-py2.7-linux-x86_64.egg', '/usr/local/lib/python2.7/dist-packages/lazy_object_proxy-1.2.2-py2.7-linux-x86_64.egg', '/usr/lib/python2.7/dist-packages']

Does anyone know why it is looking for my local path for the google module and how can I fix it?

Updates with more details about my environment:

The Google Cloud SDKs under consideration are located at:

/usr/local/lib/python2.7/dist-packages/google

if I lsshow this directory:

api auth cloud gapic gax iam ...

and if I follow these paths, all the modules will be in the places where I expect them to be given import instructions.

__init__.py, , . , , : pylint ? , " ":

https://docs.pylint.org/en/latest/user_guide/run.html?highlight=re

mypy.

+4
1

(2):

, Google App Engine, :

def fixup_paths(path):
    """Adds GAE SDK path to system path and appends it to the google path
    if that already exists."""
    # Not all Google packages are inside namespace packages, which means
    # there might be another non-namespace package named `google` already on
    # the path and simply appending the App Engine SDK to the path will not
    # work since the other package will get discovered and used first.
    # This emulates namespace packages by first searching if a `google` package
    # exists by importing it, and if so appending to its module search path.
    try:
        import google
        google.__path__.append("{0}/google".format(path))
    except ImportError:
        pass

    sys.path.insert(0, path)

# and then call later in your code:
fixup_paths(path_to_google_sdk)

, !

(1):

, : google.cloud

python 2.7 script google.cloud - . :

, Python 2.7 , . :

from __future__ import absolute_import

:

, google/cloud.py , , google, , ?

. , __init__.py, , google. , __init__.py , pylint , .

, , __init__.py google, , PEP 420 python 3 __init__.py, , , google, python 3, __init__.py, python 2.

, , , , , google-cloud-sdk, /usr/local/lib/python2.7/dist-packages, google-cloud-sdk directory python, , python, pylint, .

+2

Source: https://habr.com/ru/post/1674237/


All Articles