Bootstrap

MacOS升级指定Python版本的pip

场景:

系统默认是Python2.7,已经通过brew install [email protected] [email protected]安装了多个版本的Python

执行:pip --version

pip 24.1 from /Users/mac10.12/Library/Python/3.11/lib/python/site-packages/pip (python 3.11)

用的是Python3.11的pip,且已是最新版本

执行:python3.12 -m pip --version

pip 24.0 from /usr/local/lib/python3.12/site-packages/pip (python 3.12)

显示3.12里的pip不是最新的

这就导致,每次使用python3.12 -m venv venv创建虚拟环境之后,还需要pip install -U pip升级

尝试了`cd /usr/local/lib/python3.12/site-packages && python3.12 -m pip install --root=. -U pip`之后,把3.12的pip给整没了,报了ModuleNotFound,`python3.12 -m ensurepip`则是报了其他的错误,具体没细看,但通过如下命令解决问题了:

cd /usr/local/lib/python3.12/site-packages/
cp -r /usr/local/lib/python3.11/site-packages/pip .
cp -r /usr/local/lib/python3.11/site-packages/pip-24.0.dist-info .

即从3.11把最新的pip目录及其包信息复制到3.12就好了,重新执行如下命令,已是预期效果:

python3.12 -m pip --version
# pip 24.1 from /usr/local/lib/python3.12/site-packages/pip (python 3.12)

;