Can't import mysql.connector in Python - 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!

Related

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

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)

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.

ciscoconfparse unable to import python3.7 win10

Any new solution for this. I am unable to from ciscoconfparse import CiscoConfParse
I tried several versions of ciscoconfparse in python3 usin gpowershell in windows10.
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from ciscoconfparse import CiscoConfParse
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python3\lib\site-packages\ciscoconfparse\__init__.py", line 1, in <module>
from .ciscoconfparse import *
File "C:\Python3\lib\site-packages\ciscoconfparse\ciscoconfparse.py", line 4018
^
SyntaxError: invalid syntax
I still have not found a version that will let me import the module.
I browsed through several links here..but did not find an answer. The closest issue to mine is:
ciscoconfparse in Python 3.4 module doesn't import correctly
but not answer.
Any new info?
Thanks
I have reproduced the bug where Win10 and Python 3.7.0 cause problems.
FWIW, if you completely uninstall Python 3.7.0 (including manually deleting your Windows installation directory tree), then install Python 3.7.1, you should not have this problem with Windows 10.

No module named 'Twisted'

I just installed Python to start experimenting a bit with Scrapy.
Found a tutorial to first install Miniconda and with this I was able to install Scrapy. Now the problem is that the software I'm trying to run also requires Twisted. So I installed twisted with pip.
Twisted seems to have been installed correctly but I'm still getting an error when running the script that the Twisted module could not be found.
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
================ RESTART: C:\xampp\htdocs\crawler\crawler.py ================
Traceback (most recent call last):
File "C:\xampp\htdocs\crawler\crawler.py", line 3, in <module>
from scrapy.utils.project import get_project_settings
File "C:\xampp\htdocs\crawler\scrapy\__init__.py", line 43, in <module>
from twisted import version as _txv
ModuleNotFoundError: No module named 'twisted'
>>>
================ RESTART: C:\xampp\htdocs\crawler\crawler.py ================
Traceback (most recent call last):
File "C:\xampp\htdocs\crawler\crawler.py", line 3, in <module>
from scrapy.utils.project import get_project_settings
File "C:\xampp\htdocs\crawler\scrapy\__init__.py", line 43, in <module>
from twisted import version as _txv
ModuleNotFoundError: No module named 'twisted'
>>>
Anybody a suggestion?
Thanks in advance,
You installed twisted for python2. When you use the command pip , you are installing a package for python2. You are using python3 (3.6.3). To install twisted for python3, you have to do:
pip3 install twisted
I hope this helps.
To try if twisted correctly installed, start python interpreter and type
import twisted
If you can't import twisted, you should check if it is in your python path.
Python path can be checked in the python interpreter as
import sys
print sys.path
The directory, where your twisted is installed has to be among those folders.

ImportError: No module named _ssl occurring even when /usr/lib64/python2.7/lib-dynload/_ssl.so is available fc18

I'm seeing urlopen error when I try to do communication on HTTPS
<urlopen error unknown url type: https>
I searched for this error and found that this issue is related to ssl. I need to have _ssl.so file in my /usr/lib64/python2.7/lib-dynload/ folder. But the file is already present. I try to import ssl in python console and see the import error for ssl.
Here is the information of file
$ ll /usr/lib64/python2.7/lib-dynload/_ssl.so
-r-xr-xr-x. 1 root root 38544 Aug 9 2012 /usr/lib64/python2.7/lib-dynload/_ssl.so
And here is what I'm seeing on python console
Python 2.7.6 (default, Apr 14 2014, 02:00:55)
[GCC 4.7.2 20121109 (Red Hat 4.7.2-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "ssl.py", line 60, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: No module named _ssl
Can anybody please help me figure out the issue?
I finally figure out the issue. There were 2 python installations. The installation i was checking for openssl lib, contained the file. But by default other installation of python was being used for running the programs. Once I switched to correct python installation, the error went away.

Categories

Resources