在基于 Docker 的 Alpine Linux 图片中安装 pylint

Install pylint in Alpine Linux based Docker Image

我正在尝试安装 Pylint in a custom Docker image which is based on the Alpine Linux distribution of the official Python image。我尝试使用以下 Dockerfile:

FROM python:3.4-alpine
RUN apk add --update pylint

<< 失败

Step 2/2 : RUN apk add --update pylint
 ---> Running in 34949003816d
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  pylint (missing):
    required by: world[pylint]
The command '/bin/sh -c apk add --update pylint' returned a non-zero code: 1

此外,我试过了

FROM python:3.4-alpine
RUN pip3 install pylint

<< 这失败了

Step 2/2 : RUN pip3 install pylint
 ---> Running in b044e3347d26
Collecting pylint
  Downloading pylint-1.7.1-py2.py3-none-any.whl (641kB)
Collecting mccabe (from pylint)
  Downloading mccabe-0.6.1-py2.py3-none-any.whl
Collecting isort>=4.2.5 (from pylint)
  Downloading isort-4.2.5-py2.py3-none-any.whl (40kB)
Collecting six (from pylint)
  Downloading six-1.10.0-py2.py3-none-any.whl
Collecting astroid>=1.5.1 (from pylint)
  Downloading astroid-1.5.2-py2.py3-none-any.whl (269kB)
Collecting wrapt (from astroid>=1.5.1->pylint)
  Downloading wrapt-1.10.10.tar.gz
Collecting lazy-object-proxy (from astroid>=1.5.1->pylint)
  Downloading lazy-object-proxy-1.2.2.tar.gz
    Complete output from command python setup.py egg_info:
    running egg_info
    creating pip-egg-info/lazy_object_proxy.egg-info
    writing dependency_links to pip-egg-info/lazy_object_proxy.egg-info/dependency_links.txt
    writing top-level names to pip-egg-info/lazy_object_proxy.egg-info/top_level.txt
    writing pip-egg-info/lazy_object_proxy.egg-info/PKG-INFO
    writing manifest file 'pip-egg-info/lazy_object_proxy.egg-info/SOURCES.txt'
    warning: manifest_maker: standard file '-c' not found

    reading manifest file 'pip-egg-info/lazy_object_proxy.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    error: [Errno 2] No such file or directory: 'examples'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-1wq1n3ss/lazy-object-proxy/
The command '/bin/sh -c pip3 install pylint' returned a non-zero code: 1

最后,我尝试使用以下 Dockerfile 从源代码构建 Pylint:

FROM python:3.4-alpine
RUN apk add --update openssl
RUN wget https://github.com/PyCQA/pylint/archive/master.zip
RUN unzip master.zip
RUN cd pylint-master && python3 setup.py install

<< 现在失败了

Step 1/5 : FROM python:3.4-alpine
 ---> 9ac5db25a0ca
Step 2/5 : RUN apk add --update openssl
 ---> Using cache
 ---> d9f61f983819
Step 3/5 : RUN wget https://github.com/PyCQA/pylint/archive/master.zip
 ---> Using cache
 ---> 2a536c150b22
Step 4/5 : RUN unzip master.zip
 ---> Using cache
 ---> e160d601a015
Step 5/5 : RUN cd pylint-master && python3 setup.py install
 ---> Running in d2a20f20ff12

(...)

Searching for lazy_object_proxy
Reading https://pypi.python.org/simple/lazy_object_proxy/
Downloading https://pypi.python.org/packages/65/63/b6061968b0f3c7c52887456dfccbd07bec2303296911757d8c1cc228afe6/lazy-object-proxy-1.2.2.tar.gz#md5=841b5592bc12c6ef7e48ed1d7a5f9066
Best match: lazy-object-proxy 1.2.2
Processing lazy-object-proxy-1.2.2.tar.gz
Writing /tmp/easy_install-mxtkzpjj/lazy-object-proxy-1.2.2/setup.cfg
Running lazy-object-proxy-1.2.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-mxtkzpjj/lazy-object-proxy-1.2.2/egg-dist-tmp-f6oeoyxl
error: Setup script exited with error: [Errno 2] No such file or directory: 'examples'
The command '/bin/sh -c cd pylint-master && python3 setup.py install' returned a non-zero code: 1

知道如何安装 Pylint 吗?

似乎缺少 setuptools 的最新版本。将其添加到 Dockerfile 后,pip 安装 pylint 的方式就可以正常工作了。

FROM python:3.4-alpine
RUN pip3 install -U setuptools
RUN pip3 install -U pylint

... 并使用 Alpine 容器在 Python 3.7 上获取 pylint 运行:

FROM python:3.7-alpine
RUN apk update
RUN apk add build-base
RUN pip3 install -U pylint