Bill Goldberg
Bill Goldberg

Reputation: 1829

Python command not working while building python docker file

I need to run a python command while building a docker image. My docker file is as follows

FROM python:3.8.13-slim-buster
RUN /usr/local/bin/python3 -c "import yaml"

When I run docker build . -t hello, I get the following error:

Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM python:3.8.13-slim-buster
---> 289f4e681a96
Step 2/2 : RUN /usr/local/bin/python3 -c "import yaml"
---> Running in 4eb13a1a1e9a
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'yaml'

Upvotes: 1

Views: 866

Answers (2)

Vikrant Srivastava
Vikrant Srivastava

Reputation: 177

You need to install the pyyaml package also. You can modify your Dockerfile as below:

FROM python:3.8.13-slim-buster
RUN /usr/local/bin/pip3 install PyYAML
RUN /usr/local/bin/python3 -c "import yaml"

Upvotes: 1

Daniel Walker
Daniel Walker

Reputation: 6760

The yaml module is not a part of Python's standard library. You'll need to install it with

RUN python3 -m pip install pyyaml

Upvotes: 1

Related Questions