在python Docker容器中安装pip软件包 [英] Installing pip packages in python Docker container

查看:3458
本文介绍了在python Docker容器中安装pip软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置运行python 2.7的Docker映像.我想在容器中运行的代码取决于我试图在构建Docker映像期间使用pip的软件包.我的问题是,pip仅会获取部分软件包,而尝试获取其他软件包时会发出错误.这是我的Docker文件:

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"]

这是requiremnts.txt

An here the requiremnts.txt

Flask
redis
time
sys
opcua

Pip收集 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)

我应该怎么做才能使其与所有pip包一起使用?提前致谢!

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

推荐答案

这里的问题是时间是 Python的标准库,因此它与Python的其余部分一起安装.这意味着您不能(并且不能)通过pip安装它.这也适用于 sys .将这些从您的requirements.txt中取出,您应该会很好!

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!

这篇关于在python Docker容器中安装pip软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆