4

I am very new to docker. I am building a docker for the first time. I have created a Dockerfile and need to add python packages (specifically to emails). However I am getting an error while building the docker file.

FROM alpine MAINTAINER <[email protected]> FROM python:3.7 RUN pip install --upgrade pip && \ pip install --no-cache-dir nibabel pydicom matplotlib pillow && \ pip install --no-cache-dir med2image RUN pip install pandas xlsxwriter numpy boto boto3 botocore RUN pip install oauth2client urllib3 httplib2 email mimetypes apiclient RUN pip install snowflake.connector ENV APP_HOME /Users/username/ ENV TZ=America/Los_Angeles RUN mkdir -p $APP_HOME/code/ WORKDIR $APP_HOME ENTRYPOINT [ "python"] 

I am getting the following error:

Downloading https://files.pythonhosted.org/packages/71/e7/816030d3b0426c130040bd068be62b9213357ed02896f5d9badcf46d1b5f/email-4.0.2.tar.gz (1.2MB) Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", line 18, in <module> import setuptools.version File "/usr/local/lib/python3.7/site-packages/setuptools/version.py", line 1, in <module> import pkg_resources File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 36, in <module> import email.parser File "/tmp/pip-install-1m3cdjov/email/email/parser.py", line 10, in <module> from cStringIO import StringIO ModuleNotFoundError: No module named 'cStringIO' ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-1m3cdjov/email/ The command '/bin/sh -c pip install oauth2client urllib3 httplib2 email mimetypes apiclient' returned a non-zero code: 1 

I have installed these packages successfully in Pycharm and have no issues with it. I am not sure how to fix this in docker. Any help would be appreciated.

2
  • Looks like that module is not compatible with python 3.x. Commented Apr 22, 2019 at 17:55
  • Will be interested to see a good solution to this. I've similar issues installing pip packages with Docker and Python. I ended up running docker exec -ti my_container bash then installing with pip install. After that I'd run pip freeze > requirements.txt then install all the packages from that in the Dockerfile for all subsequent builds. Commented Apr 22, 2019 at 17:56

2 Answers 2

3

You will face a similar issue with "mimetypes" module too. Even this is part of python base and you don't need to install it manually. Also, you can have all the required modules in a requirements.txt file and install them at once. For that, you need to copy the requirements file into the docker image before running install.

requirements.txt

nibabel pydicom matplotlib pillow med2image pandas xlsxwriter numpy boto boto3 botocore oauth2client urllib3 httplib2 apiclient 

Dockerfile

FROM alpine MAINTAINER <[email protected]> FROM python:3.7 COPY requirements.txt /tmp WORKDIR /tmp RUN pip install --upgrade pip && \ pip install -r requirements.txt 
Sign up to request clarification or add additional context in comments.

1 Comment

I am pretty sure repository name must be lowercase. FROM alpine:3.7 can replace both lines 1 and 3 in the second code snippet.
2

You didn't make a mistake. The cStringIO module doesn't exist anymore. Just remove the email module from your pip install since it is already a part of python base and you should be good to go.

1 Comment

Now its giving me error with mimetypes . "Could not find a version that satisfies the requirement mimetypes (from versions: ) No matching distribution found for mimetypes" Is this also a part of python base package ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.