ModuleNotFoundError: No module named 'google'

Moved from GitHub pydgraph/80

Posted by Tails:

I’m having trouble installing pydgraph using pip, while this used to work before 2.0.0 (downgrading using pydgraph==1.2.0 does work).

Stack trace

Collecting pydgraph (from -r /runtime/app/requirements.txt (line 40))
  Downloading https://files.pythonhosted.org/packages/4d/19/025436211062e121cc344d2f34ed40e990a12a6437d3478161552bf08451/pydgraph-2.0.0.tar.gz
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-fejh1_9l/pydgraph/setup.py'"'"'; __file__='"'"'/tmp/pip-install-fejh1_9l/pydgraph/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: /tmp/pip-install-fejh1_9l/pydgraph/
    Complete output (9 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-fejh1_9l/pydgraph/setup.py", line 33, in <module>
        from pydgraph.meta import VERSION
      File "/tmp/pip-install-fejh1_9l/pydgraph/pydgraph/__init__.py", line 15, in <module>
        from pydgraph.proto.api_pb2 import Operation, Payload, Request, Response, Mutation, TxnContext,\
      File "/tmp/pip-install-fejh1_9l/pydgraph/pydgraph/proto/api_pb2.py", line 7, in <module>
        from google.protobuf import descriptor as _descriptor
    ModuleNotFoundError: No module named 'google'

Trying to install the protobuf or google packages before dgraph (as advised on StackOverflow) doesn’t make a difference.

Dockerfile

# https://github.com/aciobanu/docker-scrapy
FROM python:3.7.0-alpine3.8

WORKDIR /runtime/app

# https://unix.stackexchange.com/a/417661/299202
RUN apk add --update --no-cache openssh sshpass

RUN apk -U add \
        gcc \
        g++ \
        git \
        bash \
        libffi-dev \
        libxml2-dev \
        libxslt-dev \
        libjpeg \
        jpeg-dev \
        musl-dev \
        #openssl-dev \
        python-dev \
        python3-dev \
        py-imaging \
        py3-pillow \
        py3-lxml \
        libxml2-utils \
        linux-headers \
        py-pip \
        make \
        db-dev \
        #mariadb-dev \
        mysql-dev \
        curl \
        ca-certificates \
        rsync \
        tidyhtml \
        tidyhtml-libs \
        tidyhtml-dev \
    && update-ca-certificates \
    && rm -rf /var/cache/apk/*

# TODO: automate this away by using the python-alpine-small image with onbuild
ADD ./requirements.txt /runtime/app/requirements.txt

RUN pip3 install --upgrade pip

# https://github.com/grpc/grpc/issues/17711
RUN pip3 install cython

RUN pip3 install -r /runtime/app/requirements.txt #--target=/runtime/app/.packages

requirements.txt

google-cloud #even these packages do not fix missing google module
#google
grpcio
grpcio-tools
protobuf
pydgraph

Related:

martinmr commented :

I think this is another instance of the issue fixed by this PR: Catch pypandoc ModuleNotFoundError by robin-snt · Pull Request #81 · dgraph-io/pydgraph · GitHub

I’ll release a new version of pydgraph with that change and verify it works.

martinmr commented :

@Tails I couldn’t reproduce the issue on my machine (probably because I am not starting from an empty environment) but I released a new version of pydgraph with the fix. Can you verify it’s working again for you? version number is 2.0.1

Tails commented :

Fixed, thank you!