1.在联网电脑上创建文件夹matlplotlib_download并进入
mkdir matplotlib_download
2.创建requirements.txt文件,并写入如下内容:
touch requirements.txt
vim requirements.txt
================写入如下内容===================
numpy
six
cycler
Pillow
kiwisolver
pyparsing
python_dateutil
certifi
matplotlib
3.下载matplotlib及其依赖的包文件,whl格式
cat requirements.txt |xargs -n 1 pip3 download
4.将matlplotlib_download文件夹拷贝到离线主机上
5.根据下载的whl文件,创建新的requirements.txt文件
vim requirements.txt
=========================
contourpy-1.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
cycler-0.12.1-py3-none-any.whl
fonttools-4.53.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
kiwisolver-1.4.5-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
numpy-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
packaging-24.1-py3-none-any.whl
pillow-10.4.0-cp310-cp310-manylinux_2_28_x86_64.whl
pyparsing-3.1.2-py3-none-any.whl
six-1.16.0-py2.py3-none-any.whl
python_dateutil-2.9.0.post0-py2.py3-none-any.whl
6.使用新的requirements.txt依次安装
cat requirements.txt |xargs -n 1 pip3 install
6.如果最终matplotlib安装失败,查看缺失的依赖包xxxxx,手动安装
sudo pip3 install xxxxx.whl
xxxxx大概率是步骤3已经下载好的,直接安装即可,如果确认不存在,则可能是联网机和离网机的差异造成的,直接在联网机重新下载一份即可。