Reputation: 6044
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?
Upvotes: 2
Views: 4858
Reputation: 55
simply run
pip install firebase-admin
if not works add
pip install firebase-admin --no-deps
Upvotes: 0
Reputation: 733
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:
root@9b9176e6c26c:/# which python
/usr/local/bin/python
root@9b9176e6c26c:/# python --version
Python 2.7
Meanwhile, I have removed the part which installs Python2 from the Dockerfile and got this.
root@e6dd827dac1d:/# which python
/usr/bin/python
root@e6dd827dac1d:/# python --version
Python 2.7.15rc1
Then import what you want directly:
root@e6dd827dac1d:/# python -c "import firebase_admin"
root@e6dd827dac1d:/# 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
Upvotes: 1
Reputation: 1390
Upon building your docker image: docker build -t test -f Dockerfile .
I had different results than what you described.
echo $PYTHONPATH
returned nothing /usr/local/bin/python
allowed me to import firebase_adminFor reference:
$ which pip
/usr/bin/pip
$ /usr/bin/python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import firebase_admin
>>>
If you plan on running a script within the Dockerfile (i.e. CMD/ENTRYPOINT) I recommend passing in the full path of the working interpreter, which in this case is located at /usr/local/bin/python
Upvotes: 1