ImportError: No Module Named Google.auth

When I try to import firebase_admin in python 2.7 I get the error:

ImportError: No module named google.auth

This is the DockerFile I'm using.

I've installed Python from the source code using

tar xvzf Python-2.7.tgz
cd Python-2.7
make install

Then I've installed pip and firebase admin by running:

apt-get install -y python-pip
pip install firebase-admin

Then I ran import firebase_admin inside the python shell. I got the error:

ImportError: No module named google.auth

I've run pip show google.auth and got the following output:

Name: google-auth
Version: 1.6.3
Summary: Google Authentication Library
Author: Google Cloud Platform
Author-email: [email protected]
License: Apache 2.0
Location: /usr/local/lib/python2.7/dist-packages
Requires: cachetools, six, pyasn1-modules, rsa

I've run echo $PYTHONPATH and got this:


That means the google.auth is installed and its directory is in the PYTHONPATH, why python can't find it? and how to fix it?



I looked into the image of adamantium/flutter and saw in the Dockerfile that it depends on ubuntu:18.04 which is shipped with Python2 directly, as mentioned in PEP-394 (see the link below for more information on this).

So, I don't understand why you want to re-install it again. What happened is that you have used a Dockerfile that installs another version of Python2 in /usr/local/bin/ and overwrites the symbolic link that points to the original Python2 as you can see in docker build logs

if test -f /usr/local/bin/python -o -h /usr/local/bin/python; \
then rm -f /usr/local/bin/python; \
else true; \
(cd /usr/local/bin; ln python2.7 python)

You can then verify the current Python interpreter within the container:

[email protected]:/# which python

[email protected]:/# python --version
Python 2.7

Meanwhile, I have removed the part which installs Python2 from the Dockerfile and got this.

[email protected]:/# which python

[email protected]:/# python --version
Python 2.7.15rc1

Then import what you want directly:

[email protected]:/# python -c "import firebase_admin"

[email protected]:/# echo $?

You can see that it succeeded by returning code 0.

Dockerfile after modification:

FROM adamantium/flutter

RUN apt-get update && \
    apt-get install -y wget && \
    apt-get install -y build-essential && \
    apt-get install -y zlib1g && \
    apt-get install zlib1g-dev && \
    wget && \
    tar xvzf Python-3.6.7.tgz && \
    cd Python-3.6.7 && \
    ./configure && make && \
    make install

RUN apt-get install -y python-pip && \
    pip install firebase-admin