文章目录
编写目的
本文基于以下情况为例,介绍如何在linux上离线安装python第三方库,方法适用于所有python版本 以及所有类型的第三方库。
所需工具:另外一台装有相同python版本 能联网的Linux机器
具体问题: 需要在现场环境linux服务器上运行python脚本,该脚本需要依赖Twisted等第三方库。linux服务器上的python版本是2.7.5,该服务器未联外网,且python2.7.5默认没有自带pip工具
一、python离线安装pip
linux 默认python2.7.5版本自带没有pip工具,安装方法(适用python2 python3):
官网下载pip-20.3.1版本whl文件:
ftp上传至linux服务器执行:
python pip-20.3.1-py2.py3-none-any.whl/pip install pip-20.3.1-py2.py3-none-any.whl
二、python使用离线安装第三方库
1.获取所需第三方库的whl文件
方法一:不推荐
先使用联网的linux机器pip install 模块名
命令安装需要的第三方库,目的是为了找到对应的离线whl文件具体版本,以及依赖模块的whl文件
可以看到我们所需的whl文件有:
Twisted-20.3.0-cp27-cp27mu-manylinux1_x86_64.whl
incremental-21.3.0-py2.py3-none-any.whl
...
six-1.16.0-py2.py3-none-any.whl
接着去官网下载这些whl文件:https://pypi.org/
Realease history找对应版本 →Download files→Built Distributions
参考:https://blog.csdn.net/dietime1943/article/details/123791261
方法二:pip download命令下载(推荐)
直接使用pip download命令下载相关库安装包/以及依赖 到指定目录
root@crms-10-10-178-157[/root]# mkdir whlfile
root@crms-10-10-178-157[/root]#
root@crms-10-10-178-157[/root]# pip download Twisted -d whlfile
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting Twisted
Using cached Twisted-20.3.0-cp27-cp27mu-manylinux1_x86_64