python3 -m pip install --upgrade pip
如果pip版本过高也可降级:
pip降级pip
pip3 install --upgrade pip==<desired version>
降级(已经安装过软件包)
如果安装了高版本软件包想要降级,采用的方法其实还是上文安装指定Python包的方法,但是需要使用 -I ( --ignore-installed ) 参数表示忽略已经安装版本,或者使用强制参数 --force-reinstall :
pip降级指定python包(强制安装)
# 使用 -I 参数表示 --ignore-installed
pip install -Iv Django==3.2.21
# 或者使用 --force-reinstall
pip install --force-reinstall Django==3.2.21
我在 :ref:`` 遇到旧项目无法兼容Django 4.x ,所以强制Downgrade到 Django 3.2.21 (由于生产环境不通外网,采用 pip离线安装Python包 )
离线下载 Django-3.2.21
mkdir -p ~/onesre_venv3/whl/
# 需要特定版本的Django
pip download -d ~/onesre_venv3/whl/ Django==3.2.21
离线方式强制安装指定版本(Downgrade)输出信息
Processing ./asgiref-3.7.2-py3-none-any.whl
Processing ./Django-3.2.21-py3-none-any.whl
Processing ./pytz-2023.3.post1-py2.py3-none-any.whl
Processing ./sqlparse-0.4.4-py3-none-any.whl
Installing collected packages: pytz, sqlparse, asgiref, Django
Attempting uninstall: pytz
Found existing installation: pytz 2023.3.post1
Uninstalling pytz-2023.3.post1:
Successfully uninstalled pytz-2023.3.post1
Attempting uninstall: sqlparse
Found existing installation: sqlparse 0.4.4
Uninstalling sqlparse-0.4.4:
Successfully uninstalled sqlparse-0.4.4
Attempting uninstall: asgiref
Found existing installation: asgiref 3.7.2
Uninstalling asgiref-3.7.2:
Successfully uninstalled asgiref-3.7.2
Attempting uninstall: Django
Found existing installation: Django 4.2.5
Uninstalling Django-4.2.5:
Successfully uninstalled Django-4.2.5
Successfully installed Django-3.2.21 asgiref-3.7.2 pytz-2023.3.post1 sqlparse-0.4.4
Name: Django
Version: 4.2.5
Summary: A high-level Python web framework that encourages rapid development and clean, pragmatic design.
Home-page: https://www.djangoproject.com/
Author: Django Software Foundation
Author-email: foundation@djangoproject.com
License: BSD-3-Clause
Location: /home/admin/onesre_venv3/lib/python3.11/site-packages
Requires: asgiref, sqlparse
Required-by: django-filter, djangorestframework
执行 setup.py 安装
一些Python的软件包需要在系统中编译安装,例如 mysqlclient ,下载下来是tar包 mysqlclient-2.2.0.tar.gz ,解压缩以后,在包的根目录下有一个文件 setup.py 。那么该怎么安装呢? 😁
setup.py 方式安装Python包