linux环境使用pip下载python包

微信公众号:WELTest

linux上pip源配置

切换到对应用户,创建.pip目录。下面以root用为例:

[root@localhost ~]# mkdir ~/.pip

在~/.pip目录下创建文件pip.conf:

[root@localhost ~]# cd  ~/.pip
[root@localhost .pip]# touch pip.conf

编辑文件pip.conf,如下信息:

[global]
index = http://pypi.tuna.tsinghua.edu.cn/
index-url = http://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
timeout = 6000

至此linux上pip源配置完毕。

pip下载指定安装包

准备requirement.txt文件

给出示例文件内容为:

protobuf>=3.6.1
absl-py>=0.7.0
keras-applications>=1.0.8
tensorflow-estimator<2.1.0,>=2.0.0
termcolor>=1.1.0
grpcio>=1.8.6
google-pasta>=0.1.6
astor>=0.6.0
opt-einsum>=2.3.2
wrapt>=1.11.1
tensorboard<2.1.0,>=2.0.0
numpy<2.0,>=1.16.0
google-auth-oauthlib<0.5,>=0.4.1
requests-oauthlib>=0.7.0
oauthlib>=3.0.0
升级pip版本

如果系统提示pip版本过低,执行命令升级:

pip install --upgrade pip

执行上述命令如提示:--trusted-host,调整命令为:

pip install --upgrade pip --trusted-host pypi.tuna.tsinghua.edu.cn
下载python包

常用命令是:

pip download  -d ./tensorflow -r requirement.txt

-d:指定存放下载包路径、-r:指定请求文件

下载不同平台的python包,下面给出命令集合:

windows_x86_64:

pip download --no-deps --platform windows_x86_64 --abi none -d ./tensorflow -r requirement.txt

macosx_10_10_x86_64:

pip download --no-deps --platform macosx_10_10_x86_64 --abi none -d ./tensorflow -r requirement.txt

linux_x86_64:

pip download --no-deps --platform linux_x86_64 --abi none -d ./tensorflow -r requirement.txt
any:
pip download --no-deps --platform any --abi none -d ./tensorflow -r requirement.txt

上述命令:

–no-deps:不安装依赖包选项

–platform:安装包使用平台。默认值为当前运行系统所属平台。

–abi:指定带有python abi的安装包。如pypy_41等。通常与–impementation、–platform、–python-version选项结合使用。

发布了592 篇原创文章 · 获赞 221 · 访问量 130万+

猜你喜欢

转载自blog.csdn.net/henni_719/article/details/103272287