环境说明
(1)操作系统:centos7.7
(2)python版本:2.7.5
问题描述
在学习netconf的时候需要编写netconf自动化,此时就需要用到netconf客户端工具,需要进行安装,安装过程中出现安装失败问题,无法安装,尝试在python 3.x版本上安装可以安装成功,在windows上使用pip安装也可以正常安装,后来查找了一些其他博主的博客通过对setuptools工具进行升级解决了此问题,但是现在还不知道为何会如此,先做记录,后边有时间再补充原因
问题现象
无论是使用pip直接安装还是将tar.gz包下载到本地再安装都会出现相同的问题打印提示,如下所示
(1)pip安装:
[root@localhost ~]# pip install ncclient
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting ncclient
Using cached https://files.pythonhosted.org/packages/dd/7f/700ffea36c4c1c72d7581ef3dc3f40ec9756fd161816cd258cd303cd9f39/ncclient-0.6.7.tar.gz
ERROR: Command errored out with exit status 1:
command: /usr/bin/python2 -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"’/tmp/pip-install-DQuaAZ/ncclient/setup.py’"’"’; file=’"’"’/tmp/pip-install-DQuaAZ/ncclient/setup.py’"’"’;f=getattr(tokenize, ‘"’"‘open’"’"’, open)(file);code=f.read().replace(’"’"’\r\n’"’"’, ‘"’"’\n’"’"’);f.close();exec(compile(code, file, ‘"’"‘exec’"’"’))’ egg_info --egg-base /tmp/pip-install-DQuaAZ/ncclient/pip-egg-info
cwd: /tmp/pip-install-DQuaAZ/ncclient/
Complete output (3 lines):
/usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: ‘python_requires’
warnings.warn(msg)
error in ncclient setup command: ‘install_requires’ must be a string or list of strings containing valid project/version requirement specifiers
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
[root@localhost ~]#
(2)然后尝试下载本地后安装,依旧有相同问题:
wget https://files.pythonhosted.org/packages/dd/7f/700ffea36c4c1c72d7581ef3dc3f40ec9756fd161816cd258cd303cd9f39/ncclient-0.6.7.tar.gz
[root@localhost ncclient]# tar -zxvf ncclient-0.6.7.tar.gz
[root@localhost ncclient]# ls
ncclient-0.6.7 ncclient-0.6.7.tar.gz
[root@localhost ncclient]# cd ncclient-0.6.7
[root@localhost ncclient-0.6.7]# ls
docs examples LICENSE MANIFEST.in ncclient ncclient.egg-info PKG-INFO README README.rst requirements.txt setup.cfg setup.py test test-requirements.txt versioneer.py
[root@localhost ncclient-0.6.7]# python setup.py
/usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: ‘python_requires’
warnings.warn(msg)
error in ncclient setup command: ‘install_requires’ must be a string or list of strings containing valid project/version requirement specifiers
解决方法
升级pip和setuptools工具
[root@localhost ncclient-0.6.7]# pip install --upgrade setuptools
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting setuptools
Downloading https://files.pythonhosted.org/packages/f9/d3/955738b20d3832dfa3cd3d9b07e29a8162edb480bf988332f5e6e48ca444/setuptools-44.0.0-py2.py3-none-any.whl (583kB)
|████████████████████████████████| 583kB 46kB/s
Installing collected packages: setuptools
Found existing installation: setuptools 0.9.8
Uninstalling setuptools-0.9.8:
Successfully uninstalled setuptools-0.9.8
Successfully installed setuptools-44.0.0
[root@localhost ncclient-0.6.7]# pip install --upgrade pip
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages (19.3.1)
[root@localhost ncclient-0.6.7]#
然后在尝试安装ncclient安装成功:
[root@localhost ncclient-0.6.7]# python setup.py install
running install
running bdist_egg
running egg_info
writing requirements to ncclient.egg-info/requires.txt
writing ncclient.egg-info/PKG-INFO
writing top-level names to ncclient.egg-info/top_level.txt
writing dependency_links to ncclient.egg-info/dependency_links.txt
reading manifest file ‘ncclient.egg-info/SOURCES.txt’
reading manifest template ‘MANIFEST.in’
warning: no files found matching ‘test’
…
Using /usr/lib64/python2.7/site-packages
Searching for pycparser==2.19
Best match: pycparser 2.19
Adding pycparser 2.19 to easy-install.pth file
Using /usr/lib/python2.7/site-packages
Finished processing dependencies for ncclient==0.6.7
[root@localhost ncclient-0.6.7]#
注:
另外安装使用ncclient需要一些依赖组件也需要安装,这在ncclient网页均有说明,如下:
Requirements:
Python 2.7 or Python 3.4+
setuptools 0.6+
Paramiko 1.7+
lxml 3.3.0+
libxml2
libxslt
If you are on Debian/Ubuntu install the following libs (via aptitude or apt-get):
libxml2-dev
libxslt1-dev