我们在 AWS 上部署了一个解决方案,其中 EC2 实例使用 docker 文件为不同组件构建映像。其中一个组件有一个 docker 脚本,我们一年多来都没有更改过...
我们在 AWS 上部署了一个解决方案,其中 EC2 实例使用 docker 文件为不同组件构建映像。其中一个组件有一个 docker 脚本,我们一年多来都没有更改过,其中包括使用 pipenv 安装 python 3.9。我们最近在两天前运行它,没有任何问题。当我们今天尝试运行时,我们收到了一个我们从未见过的来自 pipenv 安装的错误。
预期结果:
脚本运行时 RUN pipenv install --python 3.9
即成功。查看上次成功运行的日志:
15:02:54 #15 [11/12] RUN pipenv install --python 3.9
15:02:55 #15 0.914 Warning: the environment variable LANG is not set!
15:02:55 #15 0.914 We recommend setting this in ~/.profile (or equivalent) for proper expected behavior.
15:02:55 #15 1.290 Creating a virtualenv for this project...
15:02:55 #15 1.290 Pipfile: /code/Pipfile
15:02:55 #15 1.316 Using /usr/bin/python3.9 (3.9.5) to create virtualenv...
15:02:56 #15 2.101 created virtual environment CPython3.9.5.final.0-64 in 476ms
15:02:56 #15 2.101 creator CPython3Posix(dest=/root/.local/share/virtualenvs/code-_Py8Si6I, clear=False, no_vcs_ignore=False, global=False)
15:02:56 #15 2.101 seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)
15:02:56 #15 2.101 added seed packages: pip==24.1, setuptools==70.1.0, wheel==0.43.0
15:02:56 #15 2.101 activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
15:02:56 #15 2.101
15:02:56 #15 2.102 Successfully created virtual environment!
15:02:56 #15 2.157 Virtualenv location: /root/.local/share/virtualenvs/code-_Py8Si6I
15:02:56 #15 2.208 To activate this project's virtualenv, run pipenv shell.
15:02:56 #15 2.208 Alternatively, run a command inside the virtualenv with pipenv run.
15:02:56 #15 2.220 To activate this project's virtualenv, run pipenv shell.
15:02:56 #15 2.220 Alternatively, run a command inside the virtualenv with pipenv run.
15:02:56 #15 2.223 Installing dependencies from Pipfile.lock (d65a77)...
实际结果:
脚本运行时 RUN pipenv install --python 3.9
失败。查看上次运行的日志:
15:49:43 #15 [11/12] RUN pipenv install --python 3.9
15:49:44 #15 0.935 Warning: the environment variable LANG is not set!
15:49:44 #15 0.935 We recommend setting this in ~/.profile (or equivalent) for proper expected behavior.
15:49:45 #15 1.345 Creating a virtualenv for this project...
15:49:45 #15 1.346 Pipfile: /code/Pipfile
15:49:45 #15 1.387 Using /usr/bin/python3.9 (3.9.5) to create virtualenv...
15:49:45 #15 1.767
15:49:45 #15 1.767 Failed creating virtual environment
15:49:45 #15 1.767 [pipenv.exceptions.VirtualenvCreationException]: Traceback (most recent call last):
15:49:45 #15 1.767 File "/usr/lib/python3.9/runpy.py", line 188, in _run_module_as_main
15:49:45 #15 1.767 mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
15:49:45 #15 1.767 File "/usr/lib/python3.9/runpy.py", line 147, in _get_module_details
15:49:45 #15 1.767 return _get_module_details(pkg_main_name, error)
15:49:45 #15 1.767 File "/usr/lib/python3.9/runpy.py", line 111, in _get_module_details
15:49:45 #15 1.767 import(pkg_name)
15:49:45 #15 1.767 File "/usr/local/lib/python3.9/dist-packages/virtualenv/init.py", line 3, in
15:49:45 #15 1.767 from .run import cli_run, session_via_cli
15:49:45 #15 1.767 File "/usr/local/lib/python3.9/dist-packages/virtualenv/run/init.py", line 15, in
15:49:45 #15 1.767 from .plugin.creators import CreatorSelector
15:49:45 #15 1.767 File "/usr/local/lib/python3.9/dist-packages/virtualenv/run/plugin/creators.py", line 7, in
15:49:45 #15 1.767 from virtualenv.create.via_global_ref.builtin.builtin_way import VirtualenvBuiltin
15:49:45 #15 1.767 File "/usr/local/lib/python3.9/dist-packages/virtualenv/create/via_global_ref/builtin/builtin_way.py", line 5, in
15:49:45 #15 1.767 from virtualenv.create.creator import Creator
15:49:45 #15 1.767 File "/usr/local/lib/python3.9/dist-packages/virtualenv/create/creator.py", line 13, in
15:49:45 #15 1.767 from virtualenv.discovery.cached_py_info import LogCmd
15:49:45 #15 1.767 File "/usr/local/lib/python3.9/dist-packages/virtualenv/discovery/cached_py_info.py", line 25, in
15:49:45 #15 1.767 _CACHE[Path(sys.executable)] = PythonInfo()
15:49:45 #15 1.767 File "/usr/local/lib/python3.9/dist-packages/virtualenv/discovery/py_info.py", line 100, in init
15:49:45 #15 1.767 self.distutils_install = self._distutils_install().copy()
15:49:45 #15 1.767 File "/usr/local/lib/python3.9/dist-packages/virtualenv/discovery/py_info.py", line 191, in _distutils_install
15:49:45 #15 1.767 i.finalize_options()
15:49:45 #15 1.767 File "/usr/local/lib/python3.9/dist-packages/setuptools/command/install.py", line 57, in finalize_options
15:49:45 #15 1.767 super().finalize_options()
15:49:45 #15 1.767 File "/usr/local/lib/python3.9/dist-packages/setuptools/_distutils/command/install.py", line 407, in finalize_options
15:49:45 #15 1.767 'dist_fullname': self.distribution.get_fullname(),
15:49:45 #15 1.767 File "/usr/local/lib/python3.9/dist-packages/setuptools/_core_metadata.py", line 266, in get_fullname
15:49:45 #15 1.767 return _distribution_fullname(self.get_name(), self.get_version())
15:49:45 #15 1.767 File "/usr/local/lib/python3.9/dist-packages/setuptools/_core_metadata.py", line 284, in _distribution_fullname
15:49:45 #15 1.767 canonicalize_version(version, strip_trailing_zero=False),
15:49:45 #15 1.767 TypeError: canonicalize_version() got an unexpected keyword argument 'strip_trailing_zero'
15:49:45 #15 1.767
15:49:45 #15 1.769 Failed to create virtual environment.
15:49:45 #15 ERROR: process "/bin/sh -c pipenv install --python 3.9" did not complete successfully: exit code: 1
15:49:45 ------
15:49:45 > [11/12] RUN pipenv install --python 3.9:
15:49:45 1.767 super().finalize_options()
15:49:45 1.767 File "/usr/local/lib/python3.9/dist-packages/setuptools/_distutils/command/install.py", line 407, in finalize_options
15:49:45 1.767 'dist_fullname': self.distribution.get_fullname(),
15:49:45 1.767 File "/usr/local/lib/python3.9/dist-packages/setuptools/_core_metadata.py", line 266, in get_fullname
15:49:45 1.767 return _distribution_fullname(self.get_name(), self.get_version())
15:49:45 1.767 File "/usr/local/lib/python3.9/dist-packages/setuptools/_core_metadata.py", line 284, in _distribution_fullname
15:49:45 1.767 canonicalize_version(version, strip_trailing_zero=False),
15:49:45 1.767 TypeError: canonicalize_version() got an unexpected keyword argument 'strip_trailing_zero'
15:49:45 1.767
15:49:45 1.769 Failed to create virtual environment.
复制步骤:
在使用以下 AMI 构建的 t2.micro AWS EC2 实例上运行以下 docker 脚本:
amzn2-ami-hvm-2.0.20230926.0-x86_64-gp2
ami-0db2efede9f8bb581
亚马逊 Linux 2 AMI 2.0.20230926.0 x86_64 HVM gp2
###############DOCKER SCRIPT START###########################
############################################################
FROM ubuntu:focal
ENV TZ=Europe/London
DEBIAN_FRONTEND=noninteractive
IS_DOCKER=true
PYTHONPATH=/code
RUN apt-get -y update
&& apt-get -y install
awscli \
ca-certificates
gnupg
gnupg1
gnupg2
libcairo2 \
libcairo2-dev \
libgeos-dev
libpq-dev
libgirepository1.0-dev
libspatialindex-dev
osm2pgsql
python3.9-dev
&& echo -n 'deb [ arch=amd64 ] https://downloads.skewed.de/apt focal main' >> /etc/apt/sources.list
&& apt-key adv --keyserver keys.openpgp.org --recv-key 612DEFB798507F25
&& apt-get -y update \
&& apt-get install python3-graph-tool=2.45 -y
RUN apt-get install -y curl
RUN curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python3.9
RUN pipenv install --python 3.9
###############DOCKER SCRIPT END#############################
############################################################
我们也遇到了这个问题。根据 https://github.com/pypa/setuptools/issues/4483 ,它似乎类似。
和 packaging
不兼容 setuptools
。
我们可以通过增加包装版本或将 setuptools 限制为旧版本来解决我们的问题。
我建议调查一下你的 python requirements.txt
希望有所帮助。