如何使用pip从需求文件中安装pkg而无需重新安装 [英] how to use pip to install pkg from requirement file without reinstall

查看:145
本文介绍了如何使用pip从需求文件中安装pkg而无需重新安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建Docker映像.我的 Dockerfile 是这样的:

I am trying to build an Docker image. My Dockerfile is like this:

FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirement.txt
CMD ["python", "manage.py", "runserver", "0.0.0.0:8300"]

还有我的 requirement.txt 文件,如下所示:

And my requirement.txt file like this:

wheel==0.29.0
numpy==1.11.3
django==1.10.5
django-cors-headers==2.0.2
gspread==0.6.2
oauth2client==4.0.0

现在,我的代码有少许更改,并且我需要 pandas ,所以我将其添加到了require.txt文件中

Now, I have a little change in my code, and i need pandas, so i add it in to requirement.txt file

wheel==0.29.0
numpy==1.11.3
pandas==0.19.2
django==1.10.5
django-cors-headers==2.0.2
gspread==0.6.2
oauth2client==4.0.0

pip install -r requirement.txt将在该文件中安装所有软件包,尽管之前几乎已经安装了所有软件包.我的问题是如何仅使pip安装 pandas ?这样可以节省创建图像的时间.

pip install -r requirement.txt will install all packages in that file, although almost of them has installed before. My question is how to make pip install pandas only? That will save the time to build image.

谢谢

推荐答案

如果用docker build -t <your_image> .更改 requirement.txt 后重建图像,我想那是不可能的,因为每次当docker运行docker build时,它将从基础映像启动一个中间容器,这是一个新环境,因此pip显然将需要安装所有依赖项.

If you rebuild your image after changing requirement.txt with docker build -t <your_image> ., I guess it cann't be done because each time when docker runs docker build, it'll start an intermediate container from base image, and it's a new environment so pip obviously will need to install all of dependencies.

您可以考虑在python:2.7上构建您自己的基础映像,并预先安装常见的依赖项,然后在您自己的基础映像上构建应用程序映像.如果需要添加更多的依赖项,请在仅安装了额外依赖项的情况下手动重建上一个基础映像,然后可以选择docker push将其返回到注册表.

You can consider to build your own base image on python:2.7 with common dependencies pre-installed, then build your application image on your own base image. Once there's a need to add more dependencies, manually re-build the base image on the previous one with only extra dependencies installed, and then maybe optionally docker push it back to your registry.

希望这会有所帮助:-)

Hope this could be helpful :-)

这篇关于如何使用pip从需求文件中安装pkg而无需重新安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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