Pip install -e 包不会出现在 Docker 中 [英] Pip install -e packages don't appear in Docker
问题描述
我有一个 requirements.txt
文件,其中包含:
I have a requirements.txt
file containing, amongst others:
Flask-RQ==0.2
-e git+https://token:x-oauth-basic@github.com/user/repo.git#egg=repo
当我尝试使用 Docker Compose 构建 Docker 容器时,它会下载两个包并安装它们,但是当我执行 pip freeze
时,没有 -e 的迹象
包.当我尝试运行该应用程序时,它看起来好像尚未安装此程序包.以下是构建的相关输出:
When I try to build a Docker container using Docker Compose, it downloads both packages, and install them both, but when I do a pip freeze
there is no sign of the -e
package. When I try to run the app, it looks as if this package hasn't been installed. Here's the relevant output from the build:
Collecting Flask-RQ==0.2 (from -r requirements.txt (line 3))
Downloading Flask-RQ-0.2.tar.gz
Obtaining repo from git+https://token:x-oauth-basic@github.com/user/repo.git#egg=repo (from -r requirements.txt (line 4))
Cloning https://token:x-oauth-basic@github.com/user/repo.git to ./src/repo
这是我的Dockerfile
:
FROM python:2.7
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY requirements.txt /usr/src/app/
RUN pip install -r requirements.txt
COPY . /usr/src/app
我觉得这种情况很奇怪,希望得到任何帮助.
I find this situation very strange and would appreciate any help.
推荐答案
我遇到了类似的问题,出现问题的一种可能方式是:
I ran into a similar issue, and one possible way that the problem can appear is from:
WORKDIR /usr/src/app
在 pip install
之前设置.pip 将在 WORKDIR 内创建 src/
目录(安装包的位置).现在所有这些都不是问题,因为您的应用文件在复制时不应覆盖 src/
目录.
being set before pip install
. pip will create the src/
directory (where the package is installed) inside of the WORKDIR. Now all of this shouldn't be an issue since your app files, when copied over, should not overwrite the src/
directory.
但是,您可能正在将卷挂载到/usr/src/app
.当你这样做时,你将覆盖 /usr/src/app/src
目录,然后你的包将不会被找到.
However, you might be mounting a volume to /usr/src/app
. When you do that, you'll overwrite the /usr/src/app/src
directory and then your package will not be found.
因此,一种解决方法是在 pip install
之后移动 WORKDIR.所以你的 Dockerfile
看起来像:
So one fix is to move WORKDIR after the pip install
. So your Dockerfile
will look like:
FROM python:2.7
RUN mkdir -p /usr/src/app
COPY requirements.txt /usr/src/app/
RUN pip install -r /usr/src/app/requirements.txt
COPY . /usr/src/app
WORKDIR /usr/src/app
这为我修好了.希望它对你有用.
This fixed it for me. Hopefully it'll work for you.
这篇关于Pip install -e 包不会出现在 Docker 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!