AttributeError: module 'firebase_admin.firestore' has no attribute 'AsyncClient' - python

I am using Firestore in my application and trying to use Python (Async) to run operations on Firestore.
I am using the example given in the official documentation here.
I am getting the below error while running db = firestore.AsyncClient().
root#54ec5947a266:/usr/src/app# python3 test.py
Traceback (most recent call last):
File "test.py", line 69, in <module>
test()
File "test.py", line 60, in test
db = firestore.AsyncClient()
AttributeError: module 'firebase_admin.firestore' has no attribute 'AsyncClient'
root#54ec5947a266:/usr/src/app#
Looks like the AsyncClient is not found.
root#5e2f7f6fc19c:/usr/src/app# python3
Python 3.5.3 (default, Apr 5 2021, 09:00:41)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from firebase_admin import firestore
>>> 'AsyncClient' in dir(firestore)
False
>>>
Could you please guide me if I am missing anything here.

AsyncClient does exist in python's firestore submodoule:
>>> from firebase_admin import firestore
>>> 'AsyncClient' in dir(firestore)
True
Make sure you have installed python's firease admin library correctly, and for your python and pip version and use firebase-admin installation guide.
(e.g. pip3 install --user firebase-admin)

Related

Can't import mysql.connector in Python

As the title says, i can't import mysql.connector in python on Debian 9.13
This is what i did
# python
Python 2.7.13 (default, Sep 26 2018, 18:42:22) [GCC 6.3.0 20170516] on
linux2 Type "help", "copyright", "credits" or "license" for more
information.
>>> import mysql.connector
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/mysql/connector/__init__.py", line 53, in <module>
from .connection import MySQLConnection
File "/usr/local/lib/python2.7/dist-packages/mysql/connector/connection.py", line 450
f"This connection is using {tls_version} which is now "
^
SyntaxError: invalid syntax
I tried installing, uninstalling and reinstalling mysql-connector, mysql-connector-python and mysql-connector-python-rf in Python2.7 and Python3
Before someone flags this question as duplicated, i already tried all the answers in this posts:
This connection is using {tls_version} which is now
Unresolved import mysql.connector PYTHON
import mysql.connector ModuleNotFoundError: No module named 'mysql.connector'; 'mysql' is not a package
mysql connector not found
ImportError: No module named 'MySQL'
This connection is using {tls_version} which is now, unable to deploy Flask application on Linux
Any help would be appreciated.
As #TimRoberts and #Dhivakar Chelladurai said in te comments, the solution is to find a version of MySQL-Connector-Python for Python2 or Python3.5 max as this is the last version that Debian 9 has for Python3.
Download:
wget https://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python_2.1.8-1debian9_all.deb
Install:
sudo dpkg -i mysql-connector-python_2.1.8-1debian9_all.deb
Thats it!

Issues importing pymssql in Python3 while using conda environment

I am having trouble importing a library called pymssql.
I have read previous solutions regarding this issue on stack overflow. The following are the solutions that did not work:
Error importing pymssql
import pymssql Unicode DecodeError in windows 7
I am running a conda virtual environment with Python 3.7.9. The following is the output when I run python in the terminal.
Python 3.7.9 (default, Aug 31 2020, 07:22:35)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
So, this confirmed that I was using the correct Python version. Next, I tried to import a library called pymssql.
This looked like:
>>> import pymssql
This returned an error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/anaconda3/envs/conda_env/lib/python3.7/site-packages/pymssql/__init__.py", line 3, in <module>
from ._pymssql import *
File "src/pymssql/_pymssql.pyx", line 1, in init pymssql._pymssql
ImportError: dlopen(/usr/local/anaconda3/envs/conda_env/lib/python3.7/site-packages/pymssql/_mssql.cpython-37m-darwin.so, 2): Symbol not found: _iconv
Referenced from: /usr/local/anaconda3/envs/conda_env/lib/python3.7/site-packages/pymssql/_mssql.cpython-37m-darwin.so
Expected in: flat namespace
in /usr/local/anaconda3/envs/conda_env/lib/python3.7/site-packages/pymssql/_mssql.cpython-37m-darwin.so
>>>
I have tried conda install pymssql and pip install pymssql. Neither of these solved the issue.

Why do I get a ModuleNotFoundError for winreg on a Linux system?

'winreg' module is not found python 3.6.7. I am not facing this problem in Python 3.4.
Is any third-party app in 'winreg' that I can use same code or how can I solve this.
jaki#jaki-notebook:~$ python3 -V
Python 3.6.7
jaki#jaki-notebook:~$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from winreg import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'winreg'
>>>
ModuleNotFoundError: No module named 'winreg'
It is not work on linux because this package expose functions of the Windows registry API to Python
Read this documentation on python offical website

Howto install psycopg2 in virtualenv with mx support?

I have a virtualenv venv where I installed mx-base and psycopg2 with pip:
$ pip freeze | grep "psyco\|mx"
egenix-mx-base==3.2.8
psycopg2==2.6
The basics of psycopg2 works but when using extensions I get exceptions like this:
Traceback (most recent call last):
File "/my_proj/my_code.py", line 32, in <module>
register_types()
File "/my_proj/my_code.py", line 28, in register_types
psycopg2.extensions.register_type(psycopg2._psycopg.MXDATETIME)
AttributeError: 'module' object has no attribute 'MXDATETIME'
Or:
ulf#kalla:~(0)(venv)$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> #Use mx.DateTime instead of pythons datetime, for compability reasons.
... psycopg2.extensions.register_type(psycopg2._psycopg.MXDATETIME)
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
AttributeError: 'module' object has no attribute 'MXDATETIME'
>>>
It seems that the installed version of psycopg2 lacks the mx-support.
How could I fix this?
You will probably need to build psycopg2 on your own, download the tar.gz, unzip, and then find the setup.cfg file, modify the mx_include parameter to be /lib/python2.7/site-packages/mx/DateTime/mxDateTime and then
python setup.py build_ext install

matplotlib: no module named compat

I have installed python-2.7.5-5ubuntu3 and matplotlib-1.3.1-1ubuntu5 from the ubuntu 14.04 repository via apt-get. Trying to import the library in python 2.7 raises the following import error:
harold#ubuntu:~$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/share/pyshared/matplotlib/__init__.py", line 157, in <module>
from matplotlib.compat import subprocess
ImportError: No module named compat
>>>
I checked the directory /usr/share/pyshared/matplotlib and, indeed, cannot find any package called compat.
Any idea what is broken on my system?
Thanks!
I have found same problem on Ubuntu 16 & 14.
Possible source of the problem is damaged instance of matplotlib. Damaged instance overlaps working instance of matplotlib.
Please try to remove broken instance of matplotlib to solve the issue.
Firstly I have looked matplotlib instances:
find / |grep matplotlib | grep __init__\.py$ |more
Secondly I have deleted this folder:
find /usr/share/pyshared/matplotlib -delete

Categories

Resources