Centos7下Python3通过Pip并通过虚拟通道安装Paramiko与Netmiko

Paramiko与Netmiko的安装:
“对于网络工程师来说,最常用的Python第三方模块无疑是用来SSH登录网络设备的Paramiko和Netmiko。首先使用命令pip3.8 install Paramiko和pip .8 instal Netmiko来分别安装它们。”

(王印老师《网络工程师的Python之路——网络运维自动化实战》,P98)

先安装Paramiko内部依赖的组件Pycrypto:

[root@zabbix-server ~]# pip3.8 install pycrypto
--------
Successfully installed pycrypto-2.6.1
WARNING: Running pip as root will break packages and permissions. You should install packages reliably by using venv: https://pip.pypa.io/warnings/venv
 
WARNING: You are using pip version 21.1.1; however, version 22.0.4 is available.
You should consider upgrading via the '/usr/local/bin/python3.8 -m pip install --upgrade pip' command.
--------

如上,有2个告警。解决两种Warning:

通过建立Python虚拟环境以解决:
[root@zabbix-server ~]# python3 -m venv tutorial-env
 
[root@zabbix-server ~]# source tutorial-env/bin/activate
 
(tutorial-env) [root@zabbix-server ~]# pip3.8 install pycrypto
--------
Successfully installed pycrypto-2.6.1
WARNING: You are using pip version 21.1.1; however, version 22.0.4 is available.
You should consider upgrading via the '/root/tutorial-env/bin/python3 -m pip install --upgrade pip' command.
--------
//如上,关于'Running pip as root will...'的Warning已经没有了
 
(tutorial-env) [root@zabbix-server ~]# /root/tutorial-env/bin/python3 -m pip install --upgrade pip
--------
equirement already satisfied: pip in ./tutorial-env/lib/python3.8/site-packages (22.0.4)
--------
//通过执行Warning分号里的内容更新pip
 
再次逐一安装组件:
(tutorial-env) [root@zabbix-server ~]# pip3.8 install pycrypto
Requirement already satisfied: pycrypto in ./tutorial-env/lib/python3.8/site-packages (2.6.1)
 
(tutorial-env) [root@zabbix-server ~]# pip3.8 install Paramiko
 
(tutorial-env) [root@zabbix-server ~]# pip3.8 install Netmiko

验证:

(tutorial-env) [root@zabbix-server ~]# python
Python 3.8.12 (default, May  8 2022, 00:35:13) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import paramiko
/root/tutorial-env/lib/python3.8/site-packages/paramiko/transport.py:236: CryptographyDeprecationWarning: Blowfish has been deprecated
  "class": algorithms.Blowfish,
>>> import netmiko
>>> 
//如上,没有报错,说明安装成功

注:退出虚拟环境命令如下:

(tutorial-env) [root@zabbix-server ~]# deactivate

你可能感兴趣的:(pip,python,linux)