CryptographyDeprecationWarning:Python 核心团队不再支持 Python 2

CryptographyDeprecationWarning:Python 核心团队不再支持 Python 2

我正在尝试运行docker-compose(通过 安装pip),但遇到以下错误:

# pip install --quiet docker-compose
# docker-compose ps
/usr/local/lib/python2.7/dist-packages/paramiko/transport.py:33: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in a future release.
  from cryptography.hazmat.backends import default_backend
Traceback (most recent call last):
  File "/usr/local/bin/docker-compose", line 7, in <module>
    from compose.cli.main import main
  File "/usr/local/lib/python2.7/dist-packages/compose/cli/main.py", line 24, in <module>
    from ..config import ConfigurationError
  File "/usr/local/lib/python2.7/dist-packages/compose/config/__init__.py", line 6, in <module>
    from .config import ConfigurationError
  File "/usr/local/lib/python2.7/dist-packages/compose/config/config.py", line 51, in <module>
    from .validation import match_named_volumes
  File "/usr/local/lib/python2.7/dist-packages/compose/config/validation.py", line 12, in <module>
    from jsonschema import Draft4Validator
  File "/usr/local/lib/python2.7/dist-packages/jsonschema/__init__.py", line 21, in <module>
    from jsonschema._types import TypeChecker
  File "/usr/local/lib/python2.7/dist-packages/jsonschema/_types.py", line 3, in <module>
    from pyrsistent import pmap
  File "/usr/local/lib/python2.7/dist-packages/pyrsistent/__init__.py", line 3, in <module>
    from pyrsistent._pmap import pmap, m, PMap
  File "/usr/local/lib/python2.7/dist-packages/pyrsistent/_pmap.py", line 98
    ) from e
         ^
SyntaxError: invalid syntax
# 

# cat /etc/debian_version 
9.13
# python2 --version
Python 2.7.13
# python3 --version
Python 3.5.3
# 

有没有办法强制docker-compose使用 python3 而不是pythonpython2)?


@Micromegas/@MikaelH

# apt-get -q install python3-pip
# pip3 install --quiet docker-compose
# docker-compose ps
/usr/local/lib/python3.5/dist-packages/paramiko/transport.py:33: CryptographyDeprecationWarning: Python 3.5 support will be dropped in the next release ofcryptography. Please upgrade your Python.
  from cryptography.hazmat.backends import default_backend
Name   Command   State   Ports
------------------------------
# 

答案1

这是 pyrsistent 的最新版本 (0.17.0) 的问题。

您应该安装过去的版本。

pip uninstall pyrsistent
pip install pyrsistent==0.16.0

答案2

我不知道这是否能解决您的问题,但我希望它能帮助您解决问题。我遇到了同样的问题,但我试图pip install docker-compose在我的 gitlab CI 中运行。

我之前出现问题的配置是这样的:

    - apk update
    - apk upgrade
    - apk add python python-dev py-pip build-base libffi-dev openssl-dev libgcc
    - pip install docker-compose

为我修复此问题的方法是:

    - apk update
    - apk upgrade
    - apk add build-base libffi-dev openssl-dev libgcc
    - apk add python3
    - apk add python3-dev
    - apk add py3-pip
    - pip3 install docker-compose

所以我认为@MikaelH 的评论是正确的。尝试更新到 pip3 并确保安装了必要的依赖项。这取决于您的环境/系统。如果您使用的是 Debian,则可以使用sudo apt-get install python3sudo apt-get install python3-pip等等sudo apt-get install python3-dev libffi-dev libssl-dev...

答案3

由于 Python 2 现已停用,因此应使用 Python 3 版本的 pip 来安装 docker-compose。在 Debian 或 Ubuntu 上,可以使用以下命令安装:

apt-get install python3-pip

之后可以使用 Python 3 pip 版本安装 Docker Compose

pip3 install docker-compose

相关内容