f“MySQL 连接器/Python C 扩展不可用 ({exc})”语法错误:语法无效

问题描述 投票:0回答:0

我正在制作一个需要 MySQL 连接的程序。我正在使用 jupyter notebook 并使用此语法建立连接:

!pip install mysql-connector-python
import pandas as pd
import numpy as np
from sklearn.neighbors import NearestNeighbors
import mysql.connector
from mysql.connector import Error

#change the value of host, user, password, database
connection = mysql.connector.connect(
  host="127.0.0.1",
  user="root",
  password="ayyi",
  database="coba"
)

它在 python 版本 3.9.13 上运行顺利 但是,我需要让我的程序适用于 python 2.7 版。在此版本中运行代码时,出现以下错误:

Requirement already satisfied: mysql-connector-python in c:\users\sayyi\anaconda2\lib\site-packages (8.0.32)
Requirement already satisfied: protobuf<=3.20.3,>=3.11.0 in c:\users\sayyi\anaconda2\lib\site-packages (from mysql-connector-python) (3.18.0)
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
  File "C:\Users\sayyi\Anaconda2\lib\site-packages\mysql\connector\connection_cext.py", line 82
    f"MySQL Connector/Python C Extension not available ({exc})"
                                                              ^
SyntaxError: invalid syntax

我一直在寻找替代方案并找到了一些尝试的建议,例如:导入 _mysql_connector 模块。但是我发现的建议似乎都没有用。

mysql database python-2.7 mysql-python mysql-connector
© www.soinside.com 2019 - 2024. All rights reserved.