我正在尝试建立一个mysql连接,它将与Python3.6.5中的SqlAlchemy一起工作。我的Dockerfile中有以下内容:
RUN pip3 install -r /event_git/requirements.txt在requirements.txt中,我还有:
mysql-connector-python==8.0.15但是,我无法连接到数据库。我还需要做什么来设置它吗?
更新:我得到了8.0.5,但不是8.0.15。显然,添加了一个协议缓冲区依赖项;有人知道如何处理它吗?
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上工作的,所以设置是可以的;我认为我只需要满足添加的protobuff依赖项(有关protobuff依赖项的信息,请参阅https://github.com/pypa/warehouse/issues/5537 )。
发布于 2019-04-10 00:31:43
mysql-connector-python将Python Protobuf作为安装要求,这意味着protobuf将随mysql-connector-python一起安装。如果这不起作用,请尝试在您的requirements.txt中添加protobuf==3.6.1。
发布于 2019-06-12 14:11:08
弄清楚了问题所在。关键是import mysql.connector需要位于create_engine所在的文件的顶部。仍然不确定确切的原因,但至少这似乎定义了_CONNECTION_POOLS = {}。如果有人知道为什么,请给出你的想法。
https://stackoverflow.com/questions/55486826
复制相似问题