没有使用Django和mysql连接器的名为'_mysql_connector'的模块-python 8.0.32

y53ybaqx  于 2023-02-25  发布在  Go
关注(0)|答案(1)|浏览(192)

我有一个Django 4.1网站,在MariaDB 10.5的Docker容器中运行良好。我只将mysql-connector-python模块从8.0.29更新到8.0.32,但现在当我启动运行Django开发服务器的Web容器时,我得到:

myproject_web | Traceback (most recent call last):
myproject_web |   File "/root/.local/share/virtualenvs/code-_Py8Si6I/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 64, in <module>
myproject_web |     import _mysql_connector
myproject_web | ModuleNotFoundError: No module named '_mysql_connector'
myproject_web | 
myproject_web | The above exception was the direct cause of the following exception:
myproject_web | 
myproject_web | Traceback (most recent call last):
myproject_web |   File "/root/.local/share/virtualenvs/code-_Py8Si6I/lib/python3.8/site-packages/mysql/connector/django/base.py", line 60, in <module>
myproject_web |     from mysql.connector.connection_cext import CMySQLConnection
myproject_web |   File "/root/.local/share/virtualenvs/code-_Py8Si6I/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 81, in <module>
myproject_web |     raise ImportError(
myproject_web | ImportError: MySQL Connector/Python C Extension not available (No module named '_mysql_connector')
myproject_web | 
myproject_web | The above exception was the direct cause of the following exception:
...

我不确定问题出在哪里,因为我对数据库服务器及其连接器等有粗略的了解。如果我将mysql-connector-python降级到8.0.29,那么它又可以工作了(我不能使用8.0.30或8.0.31,因为我希望在8.0.32中修复了一个utf8问题)。Here is its changelog.
我的docker-compose.yml为数据库容器提供了以下内容:

services:
  db:
    container_name: myproject_db
    env_file: .env
    image: mariadb:10.5
    ports:
      - 4306:3306
    restart: unless-stopped
    volumes:
      - ./docker/db/init:/docker-entrypoint-initdb.d
      - mysql_data:/var/lib/mysql

我的web容器的Dockerfile开始:

FROM python:3.8-slim-bullseye

RUN apt-get update \
    && apt-get install -y build-essential git libpq-dev libmariadb-dev mariadb-client --no-install-recommends \
    && rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man \
    && apt-get clean
ih99xse1

ih99xse11#

在Mac M1上运行Docker中的Django 3.2-4.1时也出现了同样的问题:“没有名为'_mysql_connector'的模块”
mysql-connector-python==8.0.31及更低版本可在所有系统(原生和Docker)上正确运行。
mysql-connector-python==8.0.32可以在Docker Win10下正常运行,并且可以在我们的Ubuntu服务器上部署成功,只有Mac M1会出现这个错误。
Win10 Docker容器初始化为MySQL Docker图像8.0.31-1.2.10-服务器,而Mac M1上的相同Docker容器显示“MySQL Docker图像8.0.32-1.2.11-服务器”。
对不起,这些只是线索,但这似乎是另一个M1依赖性问题。

相关问题