CryptographyDeprecationWarning:python 2不再被python核心團隊支持

分享于 

5分钟阅读

互联网

  简体

問題:

我嘗試運行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而不是python(python2)?


# 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:

這是pyristent的最新版本(0.17.0)的問題。

你應該安裝舊版本。


pip uninstall pyrsistent


pip install pyrsistent==0.16.0




答案2:

我有同樣的問題,在gitlab CI中運行pip install docker-compose有問題。

發生問題的地方是:


 - 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



嘗試更新到pip3,並確保已安裝必要的依賴項,如果在Debian上,你可以使用sudo apt-get install python3sudo apt-get install python3-pipsudo apt-get install python3-dev libffi-dev libssl-dev 等。


答案3

在Debian或Ubuntu上,可以安裝:


apt-get install python3-pip



之後,python 3pip版本可用於安裝Docker Compose


pip3 install docker-compose





相关文章