无法让 python mysql 连接器工作

Kar*_*ams 0 mysql python-3.x ubuntu-18.04

环境:Ubuntu 18.04.6 LTS,python 3.6.9,mysql Ver 14.14 Distrib 5.7.41

我添加的软件包: mysql-connector-python-py3 mysql-connector-python-py3-dbgsym

执行:

Python 3.6.9 (default, Mar 10 2023, 16:46:00) 
[GCC 8.4.0] on linux
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/lib/python3/dist-packages/mysql/connector/__init__.py", line 32, in <module>
    from .connection_cext import CMySQLConnection
  File "/usr/lib/python3/dist-packages/mysql/connector/connection_cext.py", line 40, in <module>
    from .abstracts import MySQLConnectionAbstract
  File "/usr/lib/python3/dist-packages/mysql/connector/abstracts.py", line 33
    from __future__ import annotations
    ^
SyntaxError: future feature annotations is not defined
Run Code Online (Sandbox Code Playgroud)

难道是需要安装更多的库吗?我应该期望这是通过包依赖关系来处理的?

MNB*_*MNB 6

我刚刚遇到了同样的问题(在 Ubuntu 18.04 上也是如此),并仔细阅读了 MySQL Connector Python 的发行说明,我了解到 2022 年 4 月的 Connector Python 8.0.29 中删除了对 Python 3.6 的支持。因此修复方法是降级到 8.0.28,或者首先只安装 8.0.28,并且在不以某种方式升级 python 二进制文件的情况下不要升级它。

安装稍旧的版本

python3 -m pip install "mysql-connector-python==8.0.28"
Run Code Online (Sandbox Code Playgroud)