docker安装python库_在python Docker容器中安装pip软件包

在尝试建立一个运行Python 2.7的Docker镜像时,遇到pip安装部分依赖包失败的问题。错误发生在尝试安装time、sys和opcua等包时。实际上,time和sys是Python标准库的一部分,不需要通过pip安装。只需从requirements.txt文件中移除这些包即可正常构建Docker镜像。
摘要由CSDN通过智能技术生成

I’m trying to setup a Docker image running python 2.7. The code I want to run within the container relies on packages I’m trying to get using pip during the Docker image built. My problem is that pip only gets some part of the packages issuing an error while trying to get the others. Here is my Docker file:

# Use an official Python runtime as a parent image

FROM python:2.7-slim

# Set the working directory to /app

WORKDIR /app

# Copy the current directory contents into the container at /app

ADD . /app

# Install any needed packages specified in requirements.txt

RUN pip install --trusted-host pypi.python.org -r requirements.txt

# Make port 80 available to the world outside this container

EXPOSE 80

# Define environment variable

ENV NAME World

# Run app.py when the container launches

CMD ["python", "./my_script.py"]

An here the requiremnts.txt

Flask

redis

time

sys

opcua

Pip has no problem with collecting Flask and redis, but issues error when it comes to collect time (the same problem with sys and opcua)

what should I do to make it work with all pip packages? Thanks in advance!

解决方案

The issue here is time is a part of Python's standard library, so it's installed with the rest of Python. This means you do not (and cannot) pip install it. This goes for sys as well. Take these out of your requirements.txt and you should be good to go!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值