简体   繁体   中英

Exception when trying to import python mysql connector on raspberry pi

I'm trying to use the python MySQL connector on my Raspberry PI but I'm getting this error as soon as I add the import statement to the script.

import os
import mysql.connector

The same happens when I try to import only parts of it.

import os
from mysql.connector import connect, Error

The error:

Traceback (most recent call last):
  File "script.py", line 2, in <module>
    import mysql.connector
  File "/home/pi/.local/lib/python2.7/site-packages/mysql/connector/__init__.py", line 53, in <module>
    from .connection import MySQLConnection
  File "/home/pi/.local/lib/python2.7/site-packages/mysql/connector/connection.py", line 442
    f"This connection is using {tls_version} which is now "

I used PIP to install the connector ...

pip install mysql-connector-python

... and also already tried to force-reinstall it:

pip install --upgrade --force-reinstall mysql-connector-python

This problem appears to be caused by using the default Raspbian install of Python, which is Python 2.7.

Use Python 3 instead. It is also installed on Raspbian. Use python3 and pip3 in place of python and pip .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM