旧酒换新瓶,新版M1/M2芯片Macos(Ventura)安装古早版本Python2.7(Python2.x)

向下兼容特性是软件开发系统的一个重要指标,它是指一个新的系统或者软件能够与旧的系统或软件兼容并正常运行。这意味着旧系统或软件可以在新系统或软件中使用,而不会出现问题。向下兼容对于提高软件或系统的可用性非常重要,因为它允许用户在不更换旧系统或软件的情况下使用新系统或软件。

我们知道MacOS系统从Monterey12.3版本起就移除了系统内置的Python2,更不消说最新的Ventura13.1了,但有时候我们依然需要古早版本的Python2.x来维护或者更新一些”祖传项目”,不得不承认,这类低版本的”祖传项目”在各种中大型企业内可谓是层出不穷,那么在最新的Ventura13.1系统中,就得重新安装Python2版本。

Docker构建Python2

最简单的方式是通过Docker镜像来构建Python2开发环境,通过使用容器,开发者可以轻松地将开发环境与应用程序隔离开来,这有助于避免依赖冲突和版本混乱。

直接拉取Python2的Docker镜像文件:

docker pull python:2.7.18-slim-stretch

随后运行进入Python2命令行:

docker run -it --name python2 python:2.7.18-slim-stretch

程序返回:

➜  qiniu_async docker run -it --name python2 python:2.7.18-slim-stretch
Python 2.7.18 (default, Apr 20 2020, 20:08:54)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>>

当然了,构建开发环境并非只需要开启命令行,还需要通过pip安装一些古早版本的三方依赖,此时退出Python2命令行:

exit()

随后查看Python2的容器id

➜  ~ docker ps
CONTAINER ID   IMAGE                        COMMAND     CREATED         STATUS         PORTS     NAMES
41ef4af5169d   python:2.7.18-slim-stretch   "python2"   8 minutes ago   Up 5 minutes             python2
➜  ~

进入容器内终端:

docker exec -it 41ef4af5169d /bin/sh

此时,就可是使用pip命令来安装一些老版本的软件了,比如说Django:

pip install django@1.11.29

程序返回:

`
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting django
Downloading Django-1.11.29-py2.py3-none-any.whl (6.9 MB)
|████████████████████████████████| 6.9 MB 8.9 MB/s
Collecting pytz
Downloading pytz-2022.7-py2.py3-none-any.whl (499 kB)
|████████████████████████████████| 499 kB 20.7 MB/s
Installing collected packages: pytz, django
Successfully installed django-1.11.29 pytz-2022.7
WARNING: You are using pip version 20.0.2; however, version 20.3.4 is available.

You should consider upgrading via the ‘/usr/local/bin/python -m pip install –upgrade pip’ command.

pip list
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Package Version

Original: https://www.cnblogs.com/v3ucn/p/17024069.html
Author: 刘悦的技术博客
Title: 旧酒换新瓶,新版M1/M2芯片Macos(Ventura)安装古早版本Python2.7(Python2.x)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/807956/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球