简体   繁体   English

尝试在树莓派上导入 python mysql 连接器时出现异常

[英]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.我正在尝试在我的 Raspberry PI 上使用 python MySQL 连接器,但是一旦我将导入语句添加到脚本中,我就会收到此错误。

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 来安装连接器...

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.此问题似乎是由使用 Python 的默认 Raspbian 安装(即 Python 2.7)引起的。

Use Python 3 instead.请改用 Python 3。 It is also installed on Raspbian.它也安装在 Raspbian 上。 Use python3 and pip3 in place of python and pip .使用python3pip3代替pythonpip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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