DistributionNotFound运行与pserve当搬运工,撰写
问题描述:
我试图运行与码头工人,撰写我的简单的金字塔应用,下面是我的搬运工文件:DistributionNotFound运行与pserve当搬运工,撰写
Dockerfile:
FROM python:2.7-onbuild
RUN pip install --no-cache-dir -r requirements_dev.txt
docker- compose.yml
db:
image: mysql:5.6
web:
build: .
command: pserve development.ini --reload
volumes:
- .:/usr/src/app
ports:
- "6543:6543"
links:
- db:db
当我运行docker-compose up
我得到pkg_resources.DistributionNotFound: The 'tenders' distribution was not found and is required by the application
,这很奇怪,因为我的应用程序应该已经安装了使用pip install -e .
命令。当我启动pserve development.ini --reload
它工作得很好
docker-compose run web bash
[email protected]:/tenders# pip freeze | grep tenders # no results
[email protected]:/tenders# pip install -e .
Obtaining file:///tenders
# Skippping most of the outup for more readability
Installing collected packages: tenders
Running setup.py develop for tenders
Successfully installed tenders
[email protected]:/tenders# pip freeze | grep tenders
-e [email protected]:xxx/[email protected]#egg=tenders-master
现在:
事情变得怪异。
我在做什么错,我如何使用pip install -e .
(或任何其他命令)自动安装我的包tenders
?
答
我有同样的问题。当docker卷被挂载时发生。
在您的Dockerfile中,您安装了应用程序pip install -e .
,该应用程序在当前目录(在图像中)中创建.egg-info目录。但后来,当您使用docker卷来替换容器源目录时,您的主机文件系统中没有该.egg-info目录。
我修复它的方式是我在我的主机文件系统中创建了一个virtualenv,我运行了python setup.py develop
,但我想你可以运行pip install -e .
。它创建.egg-info目录,以便在从容器中运行pserve
时存在该目录。 virtualenv可能在那时可能被删除。
我真的不确定这是最好的解决方案,但至少现在你知道问题的原因了。
感谢您的回复。所以你建议修改Dockerfile,创建并激活virtualenv然后安装软件包? – matino
不,我在主机文件系统中创建了virtualenv,以便主文件系统中存在.egg-info文件夹。然后,当您启动Docker容器并装入卷时,图像目录将被删除,但来自主机的新目录也将被作为.egg-info目录。这真的不完美,可能有更优雅的解决方案。 –
对不起,我不明白这一点:'但是后来,当你使用docker卷来替换你的容器源目录时,你的主机文件系统中没有这个.egg-info目录。为什么我没有该目录和我的应用程序目录存在(注意 - 我不再删除Dockerfile中的.egg目录 - 请参阅我的编辑)? – matino