我是Docker的新手.我是第一次构建docker.我已经创建了一个Dockerfile,并且需要添加python包(特别是电子邮件).但是在构建docker文件时出现错误.
FROM alpine
MAINTAINER
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"]
我收到以下错误:
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 "", line 1, in
File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", line 18, in
import setuptools.version
File "/usr/local/lib/python3.7/site-packages/setuptools/version.py", line 1, in
import pkg_resources
File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 36, in
import email.parser
File "/tmp/pip-install-1m3cdjov/email/email/parser.py", line 10, in
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
我已经在Pycharm中成功安装了这些软件包,并且没有任何问题.我不确定如何在docker中修复此问题.任何帮助,将不胜感激.
解决方法:
您也会遇到“ mimetypes”模块的类似问题.即使这是python base的一部分,您也无需手动安装.另外,您可以将所有必需的模块包含在requirements.txt文件中,并立即安装它们.为此,您需要在运行安装之前将需求文件复制到Docker映像中.
requirements.txt
nibabel
pydicom
matplotlib
pillow
med2image
pandas
xlsxwriter
numpy
boto
boto3
botocore
oauth2client
urllib3
httplib2
apiclient
Docker文件
FROM alpine
MAINTAINER
FROM python:3.7
COPY requirements.txt /tmp
WORKDIR /tmp
RUN pip install --upgrade pip && \
pip install -r requirements.txt
标签:docker,dockerfile,python
来源: https://codeday.me/bug/20191108/2005645.html