简体   繁体   English

无法将 Python Package 安装到 Docker

[英]Can't Install Python Package onto Docker

Trying to install a package (flake8) onto a Docker container (or maybe it's an image).尝试将 package (flake8) 安装到 Docker 容器(或者可能是图像)上。 I've pip installed the package locally, and when I try to pip install it again, I get:我已经 pip 在本地安装了 package,当我再次尝试 pip 安装时,我得到:

Requirement already satisfied: flake8 in c:\python39\lib\site-packages (5.0.4)

But then when I run this code snippet:但是当我运行这个代码片段时:

docker-compose run --rm app sh -c "flake8"

I get the following error:我收到以下错误:

sh: flake8: not found

Using VSCode.使用VS代码。 Any ideas?有任何想法吗? Thanks谢谢

Use the following command to install in the docker container instead of in the base environment:使用以下命令在 docker 容器中安装,而不是在基础环境中安装:

pip install flake8

The issue was that Flake8 was only installed locally as opposed to on the Docker image (See David's comment above for more on this).问题是 Flake8 仅安装在本地,而不是安装在 Docker 图像上(有关更多信息,请参见上面 David 的评论)。

To remedy this, the following line was added to a requirements.txt file (the numbers were for the version of the package):为了解决这个问题,将以下行添加到 requirements.txt 文件中(数字代表包的版本):

flake8>=3.9.2,<3.10

And then in the Dockerfile:然后在 Dockerfile 中:

/py/bin/pip install -r /tmp/requirements.txt && \

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM