Can't Install Python Package onto Docker

Question:

Trying to install a package (flake8) onto a Docker container (or maybe it’s an image). I’ve pip installed the package locally, and when I try to pip install it again, I get:

Requirement already satisfied: flake8 in c:python39libsite-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. Any ideas? Thanks

Asked By: Conor Romano

||

Answers:

Use the following command to install in the docker container instead of in the base environment:

pip install flake8
Answered By: MingJie-MSFT

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).

To remedy this, the following line was added to a requirements.txt file (the numbers were for the version of the package):

flake8>=3.9.2,<3.10

And then in the Dockerfile:

/py/bin/pip install -r /tmp/requirements.txt && 
Answered By: Conor Romano