docker 中的 Pipenv 无法安装包

Pipenv in docker fails to install packages

我有以下 Pipfile:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
mypy = "==0.521"

[requires]
python_version = "3.6"

Dockerfile:

FROM heroku/heroku:18

#Install system dependencies
RUN apt-get update && apt-get install -y software-properties-common build-essential curl nano

#Install python 3.6
RUN apt-get update
RUN apt-get install -y python3.6 libpython3.6 python3.6-dev python-dev python-pip \
    python3-pip libssl-dev libffi-dev libxml2-dev libxslt1-dev zlib1g-dev

#Install backend packages
RUN pip3 install pipenv python-magic libmagic django
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8

镜像构建和启动容器

docker build -t test -f Dockerfile .
docker run -it test /bin/bash

将 Pipfile 复制到容器

docker cp Pipfile <container>:/test/Pipfile

生成锁文件

pipenv lock

正在尝试安装包

pipenv install --dev --system --python=`which python3`

错误

    An error occurred while installing mypy==0.521! Will try again.
An error occurred while installing typed-ast==1.0.4! Will try again.
     ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 2/2 — 00:00:01
Installing initially failed dependencies...
Collecting mypy==0.521 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/2 — 00:00:00
  Using cached https://files.pythonhosted.org/packages/18/11/733e33decfdbd76cce7158c92618b9317d4132b41affd04db00216d17f76/mypy-0.521.tar.gz
    Complete output from command python setup.py egg_info:
    ERROR: You need Python 3.2 or later to use mypy.

    ----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-cebwoI/mypy/

  ☤  ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/2 —

问题出在--system。这使得 pipenv 使用 pip 命令——解析为 /usr/bin/pip,即 2.7 pip。
我看到如果您删除 --system 标志,它将 运行 正确。

root@5ce055e3cd89:~# pipenv install --dev --python 3
Virtualenv already exists!
Removing existing virtualenv...
Creating a virtualenv for this project...
Pipfile: /root/Pipfile
Using /usr/bin/python3 (3.6.6) to create virtualenv...
⠋Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /root/.local/share/virtualenvs/root-BuDEOXnJ/bin/python3
Also creating executable in /root/.local/share/virtualenvs/root-BuDEOXnJ/bin/python
Installing setuptools, pip, wheel...done.
Setting project for root-BuDEOXnJ to /root

Virtualenv location: /root/.local/share/virtualenvs/root-BuDEOXnJ
Installing dependencies from Pipfile.lock (0f51af)...
     ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 2/2 — 00:00:01
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.