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
wget https://www.python.org/ftp/python/2.7/Python-2.7.tgz
tar xvzf Python-2.7.tgz
cd Python-2.7
./configure
make
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
Home-page: https://github.com/GoogleCloudPlatform/google-auth-
library-python
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:
/usr/local/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages
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?
Answer
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).
https://www.python.org/dev/peps/pep-0394/
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; \
fi
(cd /usr/local/bin; ln python2.7 python)
You can then verify the current Python interpreter within the container:
[email protected]:/# which python
/usr/local/bin/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
/usr/bin/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 $?
0
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 https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tgz && \
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
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module