由于公司的服务器处于与外网隔离的状态,安装第三方包比较麻烦,故写此文章,仅供参考。

1. 在本机虚拟机(物理机)联网执行

直接执行:pip download -d /home/pkgs tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple
或者将需要安装的软件写入requirement.txt 执行pip download -d /home/pkgs -r requirement.txt

以在公司服务器上安装tensorflow等开发环境为例(离线安装):

#!/usr/bin/bash

echo "下载前的准备..."
username="username"
cd /home/$usernme
mkdir -p /home/$usernme/pkgs
cat > requirement.txt <<"EOF"
tensorflow==2.2.0
scikit-image==0.15.0
scikit-learn==0.24.2
opencv-python==4.5.2.52
numpy
pandas
requests
flask
EOF

echo "下载中..."
pip download \
-d /home/$usernme/pkgs \
-r requirement.txt \
-i https://pypi.tuna.tsinghua.edu.cn/simple \
--proxy=http://192.168.110.111

echo "打包压缩文件..."
tar -zcvf tensorflow_and_other_file.tar.gz pkgs

二、离线安装

pip install --no-index --find-links=/home/pkgs tensorflow
pip install --no-index --find-links=/home/pkgs -r requirements.txt

鸣谢:
https://www.cnblogs.com/michael-xiang/p/5690746.html

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐