user12073121
user12073121

Reputation: 81

Python packages install on AmazonLinux

I'm building AWS Batch jobs.

I have python3 package which is built into a AmazonLinux based docker image. I need to install boto3, pandas, s3fs and couple of other modules. I have set commands in the Dockerfile to install the modules along with python3.

I call an entry script, which calls out other src python files.

I get an error no module named boto3, as the output of my batch job.

I'm guessing the problem is with AmazonLinux as it defaults to python2 and python3 packages aren't found.

How do I install the packages in my docker image which my package can consume?

Upvotes: 2

Views: 5537

Answers (1)

Nathan Collins
Nathan Collins

Reputation: 341

I put together a trivial example of a Batch image that includes some pip packages: https://github.com/nathantheinventor/sample-batch-image, and it builds and runs with no errors.

Here's the Dockerfile:

FROM amazonlinux:2
RUN yum install -y python3 python3-pip
RUN python3 -m pip install boto3 pandas s3fs
COPY src /code
ENTRYPOINT [ "python3", "/code/main.py" ]

For what it's worth, I would recommend using python:3.8 as a base image rather than AmazonLinux because it already has the python environment set up correctly with pip, and you don't have to worry about running Python 2 by accident.

Upvotes: 4

Related Questions