3.6.1 Fabric的安装
安装Fabric时,可以选择采用Python的pip、easy_install及源码安装方式,这些方式能够很方便地解决包依赖关系。大家可以根据系统环境自行选择最优的安装方法,如果选择pip或easy_install安装方式,则其安装命令如下(如果系统是最小化安装,记得先提前安装好gcc、gcc-c++、make这些基础开发包和python-pip):
yum -y install make gcc gcc++ python-devel python-pip
pip是安装Python包的工具,提供了安装包、列出已经安装的包、升级包及卸载包的功能,可以通过pip工具直接安装Fabric,命令如下:
pip install fabric
这里推荐源码安装,安装步骤如下所示:
yum -y install python-setuptools
cd /usr/local/src
wget https://pypi.python.org/packages/source/F/Fabric/Fabric-1.3.0.tar.gz --no-check-certificate
tar xvf Fabric-1.3.0.tar.gz
cd Fabric-1.3.0
python setup.py install
安装结果如下,如果出现以下信息则表示Fabric已经成功安装:
Downloading https://pypi.python.org/packages/source/s/ssh/ssh-1.8.0.tar.gz#md5=bc4dd59ec0c7bdf78a3840652cac824e
Processing ssh-1.8.0.tar.gz
Running ssh-1.8.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-Cw9PkJ/ssh-1.8.0/egg-dist-tmp-dkm93k
zip_safe flag not set; analyzing archive contents...
Adding ssh 1.8.0 to easy-install.pth file
Installed /usr/lib/python2.6/site-packages/ssh-1.8.0-py2.6.egg
Searching for pycrypto==2.6.1
Best match: pycrypto 2.6.1
Adding pycrypto 2.6.1 to easy-install.pth file
Using /usr/lib64/python2.6/site-packages
Finished processing dependencies for Fabric==1.3.0
下面检查下Fabric模块是否正常安装成功了,如果输入import fabric没有任何错误提示则表示已经成功安装,命令如下所示:
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import fabric
>>>