python 未找到模块错误:Dockerized Django Application中没有名为“Kafka.vendor.six.moves”的模块

6pp0gazn  于 2023-10-14  发布在  Python
关注(0)|答案(1)|浏览(432)

我的Dockerized Django应用程序遇到了问题。我正在使用以下Dockerfile来构建我的应用程序:

FROM python:alpine

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV DJANGO_SUPERUSER_PASSWORD datahub

RUN mkdir app
WORKDIR /app
COPY ./app .
RUN mkdir -p volumes

RUN apk update
RUN apk add --no-cache gcc python3-dev musl-dev mariadb-dev

RUN pip3 install --upgrade pip
RUN pip3 install -r requirements.txt

RUN apk del gcc python3-dev musl-dev

CMD python3 manage.py makemigrations --noinput &&\
    while ! python3 manage.py migrate --noinput; do sleep 1; done && \ 
    python3 manage.py collectstatic --noinput &&\
    python3 manage.py createsuperuser --user datahub  --email admin@localhost --noinput;\
    python3 manage.py runserver 0.0.0.0:8000

在我的requirements.txt文件中:

kafka-python==2.0.2

当我在Docker容器中运行我的应用程序时,我遇到了以下错误:

ModuleNotFoundError: No module named 'kafka.vendor.six.moves'

完成错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.12/site-packages/kafka/__init__.py", line 23, in <module>
    from kafka.consumer import KafkaConsumer
  File "/usr/local/lib/python3.12/site-packages/kafka/consumer/__init__.py", line 3, in <module>
    from kafka.consumer.group import KafkaConsumer
  File "/usr/local/lib/python3.12/site-packages/kafka/consumer/group.py", line 13, in <module>
    from kafka.consumer.fetcher import Fetcher
  File "/usr/local/lib/python3.12/site-packages/kafka/consumer/fetcher.py", line 19, in <module>
    from kafka.record import MemoryRecords
  File "/usr/local/lib/python3.12/site-packages/kafka/record/__init__.py", line 1, in <module>
    from kafka.record.memory_records import MemoryRecords, MemoryRecordsBuilder
  File "/usr/local/lib/python3.12/site-packages/kafka/record/memory_records.py", line 27, in <module>
    from kafka.record.legacy_records import LegacyRecordBatch, LegacyRecordBatchBuilder
  File "/usr/local/lib/python3.12/site-packages/kafka/record/legacy_records.py", line 50, in <module>
    from kafka.codec import (
  File "/usr/local/lib/python3.12/site-packages/kafka/codec.py", line 9, in <module>
    from kafka.vendor.six.moves import range
ModuleNotFoundError: No module named 'kafka.vendor.six.moves'

我已经尝试过更新Kafka包,检查依赖关系,并手动安装six包。然而,这个问题仍然存在。有谁能提供一些见解来解决这个错误吗?
提前感谢您的帮助!

bmp9r5qi

bmp9r5qi1#

这似乎是一个Python 3.12的问题,我有同样的错误,但在一个完全不同的上下文中。
而不是FROM python:alpine
建议使用FROM python:3.11
3.12仍然是非常新的,有许多项目仍在努力解决问题。

相关问题