python-3.x - 在Docker文件中设置mysql-connector-python

标签 python-3.x docker dockerfile protocol-buffers mysql-connector-python

我试图建立一个可以在python 3.6.5中与SqlAlchemy一起使用的mysql连接。我的Dockerfile中有以下内容:

RUN pip3 install -r /event_git/requirements.txt

我也有,在requirements.txt中:
mysql-connector-python==8.0.15

但是,我无法连接到数据库。我还有什么要做的设置吗?

更新:
我可以使用8.0.5,但不能使用8.0.15。显然,增加了一个probbuff依赖关系。有谁知道该如何处理?

docker 文件是:
RUN apt-get -y update && apt-get install -y python3 python3-pip fontconfig wget nodejs nodejs-legacy npm
RUN pip3 install --upgrade pip
# Copy contents of this directory (i.e. full source) to image
COPY . /my_project
# Install Python dependencies
RUN pip3 install -r /event_git/requirements.txt
# Set event_git folder as working directory
WORKDIR /my_project
ENV LANG C.UTF-8

我正在通过运行
docker build -t event_git .;docker run -t -i event_git /bin/bash

然后执行脚本;该数据库位于我的本地计算机上。这可以在mysql-connector-python == 8.0.5上运行,但不能在8.0.15上运行,因此安装正常。我想我只需要实现添加的probbuff依赖关系(有关protobuff依赖关系的信息,请参见https://github.com/pypa/warehouse/issues/5537)。

最佳答案

mysql-connector-python具有Python Protobuf作为安装要求,这意味着protobuf将与mysql-connector-python一起安装。
如果这不起作用,请尝试在您的requirements.txt中添加protobuf==3.6.1

关于python-3.x - 在Docker文件中设置mysql-connector-python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55486826/

相关文章:

python - ImportError : attempted relative import with no known parent package :(

python - 如何检查在 Python 中使用 Walrus 运算符时是否按下了 Enter 键?

java - 无法读取 jar 文件中的文件

docker - 如何使用Dockerfile管理特定版本的构建

docker - 在Docker容器中安装Docker => D-Bus连接错误

python - 使用Python中不同大小网格点的数据生成3D曲面图

python - 将类似dict的字符串转换为JSON

java - 在Docker镜像中安装Maven/java软件包而不启动Spring Boot

docker - 为什么我的节点中会出现 "curl: not found":alpine Docker container?

python - 如何使用 docker-py 中的副本将文件从容器复制到主机