python setuptools安装与
python本身自带了一套工具distutils ,用于发布 Python 应用程序。但 distutils 没有提供定义其它依赖包的功能,setuptools 的真正优点并不在于实现distutils 所能实现的功能——尽管它的确增强了distutils的功能并简化了setup.py 脚本中的内容。setuptools 最大的优势是它在包管理能力方面的增强。它可以使用一种更加透明的方法来查找、下载并安装依赖包;并可以在一个包的多个版本中自由进行切换,这些版本都安装在同一个系统上;也可以声明对某个包的特定版本的需求;还可以只使用一个简单的命令就能更新到某个包的最新版本。
简单来说,Python setuptools可以看做是增强版的distutils,用来管理Python的各种包。
一般在Centos系统安装完成后,Python编译器就已经会安装好了,对于setuptools工具的安装,可以用ea_setup.py脚本的方法,自动下载安装包并安装;也可以先下载完整的setuptools安装包,然后再单独安装。
一、以ez_setup.py脚本方式安装setuptools工具
使用ez_setup.py脚本的方法比较简单,但要注意服务器要能够联网下载软件包,安装命令为:
# cd /usr/local/src/
# wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py
# python ez_setup.py --insecure
安装的过程为:
# wget --no-check-certificate Https://bootstrap.pypa.io/ez_setup.py
--2015-08-27 10:43:48-- https://bootstrap.pypa.io/ez_setup.py
Resolving bootstrap.pypa.io... 103.245.222.175
Connecting to bootstrap.pypa.io|103.245.222.175|:443... connected.
WARNING: certificate common name “*.c.ssl.fastly.net” doesn’t match requested host name “bootstrap.pypa.io”.
HTTP request sent, awaiting response... 200 OK
Length: 11432 (11K) [text/x-python]
Saving to: “ez_setup.py”
100%[===================================================================>] 11,432 --.-K/s in 0s
2015-08-27 10:43:49 (692 MB/s) - “ez_setup.py” saved [11432/11432]
#
# python ez_setup.py --insecure
Downloading https://pypi.python.org/packages/source/s/setuptools/setuptools-18.2.zip
Extracting in /tmp/tmpn65Wy1
Now working in /tmp/tmpn65Wy1/setuptools-18.2
Installing Setuptools
running install
running bdist_egg
running egg_info
writing requirements to setuptools.egg-info/requires.txt
writing setuptools.egg-info/PKG-INFO
writing top-level names to setuptools.egg-info/top_level.txt
writing dependency_links to setuptools.egg-info/dependency_links.txt
writing entry points to setuptools.egg-info/entry_points.txt
writing requirements to setuptools.egg-info/requires.txt
writing setuptools.egg-info/PKG-INFO
writing top-level names to setuptools.egg-info/top_level.txt
writing dependency_links to setuptools.egg-info/dependency_links.txt
writing entry points to setuptools.egg-info/entry_points.txt
reading manifest file 'setuptools.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'setuptools.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib
copying easy_install.py -> build/lib
creating build/lib/setuptools
copying setuptools/py26compat.py -> build/lib/setuptools
copying setuptools/unicode_utils.py -> build/lib/setuptools
copying setuptools/py31compat.py -> build/lib/setuptools
copying setuptools/windows_support.py -> build/lib/setuptools
copying setuptools/package_index.py -> build/lib/setuptools
copying setuptools/arcHive_util.py -> build/lib/setuptools
copying setuptools/dist.py -> build/lib/setuptools
copying setuptools/py27compat.py -> build/lib/setuptools
copying setuptools/msvc9_support.py -> build/lib/setuptools
copying setuptools/version.py -> build/lib/setuptools
copying setuptools/compat.py -> build/lib/setuptools
copying setuptools/__init__.py -> build/lib/setuptools
copying setuptools/utils.py -> build/lib/setuptools
copying setuptools/sandbox.py -> build/lib/setuptools
copying setuptools/extension.py -> build/lib/setuptools
copying setuptools/lib2to3_ex.py -> build/lib/setuptools
copying setuptools/depends.py -> build/lib/setuptools
copying setuptools/ssl_support.py -> build/lib/setuptools
copying setuptools/site-patch.py -> build/lib/setuptools
creating build/lib/_markerlib
copying _markerlib/markers.py -> build/lib/_markerlib
copying _markerlib/__init__.py -> build/lib/_markerlib
creating build/lib/pkg_resources
copying pkg_resources/__init__.py -> build/lib/pkg_resources
creating build/lib/setuptools/command
copying setuptools/command/bdist_rpm.py -> build/lib/setuptools/command
copying setuptools/command/develop.py -> build/lib/setuptools/command
copying setuptools/command/build_ext.py -> build/lib/setuptools/command
copying setuptools/command/install.py -> build/lib/setuptools/command
copying setuptools/command/upload_docs.py -> build/lib/setuptools/command
copying setuptools/command/reGISter.py -> build/lib/setuptools/command
copying setuptools/command/build_py.py -> build/lib/setuptools/command
copying setuptools/command/saveopts.py -> build/lib/setuptools/command
copying setuptools/command/alias.py -> build/lib/setuptools/command
copying setuptools/command/install_egg_info.py -> build/lib/setuptools/command
copying setuptools/command/__init__.py -> build/lib/setuptools/command
copying setuptools/command/test.py -> build/lib/setuptools/command
copying setuptools/command/easy_install.py -> build/lib/setuptools/command
copying setuptools/command/rotate.py -> build/lib/setuptools/command
copying setuptools/command/sdist.py -> build/lib/setuptools/command
copying setuptools/command/setopt.py -> build/lib/setuptools/command
copying setuptools/command/egg_info.py -> build/lib/setuptools/command
copying setuptools/command/bdist_egg.py -> build/lib/setuptools/command
copying setuptools/command/install_scripts.py -> build/lib/setuptools/command
copying setuptools/command/install_lib.py -> build/lib/setuptools/command
copying setuptools/command/bdist_wininst.py -> build/lib/setuptools/command
creating build/lib/pkg_resources/_vendor
copying pkg_resources/_vendor/__init__.py -> build/lib/pkg_resources/_vendor
creating build/lib/pkg_resources/_vendor/packaging
copying pkg_resources/_vendor/packaging/_structures.py -> build/lib/pkg_resources/_vendor/packaging
copying pkg_resources/_vendor/packaging/__about__.py -> build/lib/pkg_resources/_vendor/packaging
copying pkg_resources/_vendor/packaging/specifiers.py -> build/lib/pkg_resources/_vendor/packaging
copying pkg_resources/_vendor/packaging/version.py -> build/lib/pkg_resources/_vendor/packaging
copying pkg_resources/_vendor/packaging/__init__.py -> build/lib/pkg_resources/_vendor/packaging
copying pkg_resources/_vendor/packaging/_compat.py -> build/lib/pkg_resources/_vendor/packaging
copying setuptools/script (dev).tmpl -> build/lib/setuptools
copying setuptools/script.tmpl -> build/lib/setuptools
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/py26compat.py -> build/bdist.linux-x86_64/egg/setuptools
creating build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/bdist_rpm.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/develop.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/build_ext.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/install.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/upload_docs.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/register.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/build_py.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/saveopts.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/alias.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/install_egg_info.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/__init__.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/test.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/easy_install.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/rotate.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/sdist.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/setopt.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/egg_info.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/bdist_egg.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/install_scripts.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/install_lib.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/bdist_wininst.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/unicode_utils.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/py31compat.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/windows_support.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/script.tmpl -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/package_index.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/archive_util.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/dist.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/script (dev).tmpl -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/py27compat.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/msvc9_support.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/version.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/compat.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/__init__.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/utils.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/sandbox.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/extension.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/lib2to3_ex.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/depends.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/ssl_support.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/site-patch.py -> build/bdist.linux-x86_64/egg/setuptools
creating build/bdist.linux-x86_64/egg/_markerlib
copying build/lib/_markerlib/markers.py -> build/bdist.linux-x86_64/egg/_markerlib
copying build/lib/_markerlib/__init__.py -> build/bdist.linux-x86_64/egg/_markerlib
copying build/lib/easy_install.py -> build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/pkg_resources
copying build/lib/pkg_resources/__init__.py -> build/bdist.linux-x86_64/egg/pkg_resources
creating build/bdist.linux-x86_64/egg/pkg_resources/_vendor
copying build/lib/pkg_resources/_vendor/__init__.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor
creating build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging
copying build/lib/pkg_resources/_vendor/packaging/_structures.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging
copying build/lib/pkg_resources/_vendor/packaging/__about__.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging
copying build/lib/pkg_resources/_vendor/packaging/specifiers.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging
copying build/lib/pkg_resources/_vendor/packaging/version.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging
copying build/lib/pkg_resources/_vendor/packaging/__init__.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging
copying build/lib/pkg_resources/_vendor/packaging/_compat.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging
byte-compiling build/bdist.linux-x86_64/egg/setuptools/py26compat.py to py26compat.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/bdist_rpm.py to bdist_rpm.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/develop.py to develop.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/build_ext.py to build_ext.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/install.py to install.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/upload_docs.py to upload_docs.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/register.py to register.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/build_py.py to build_py.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/saveopts.py to saveopts.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/alias.py to alias.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/install_egg_info.py to install_egg_info.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/test.py to test.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py to easy_install.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/rotate.py to rotate.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/sdist.py to sdist.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/setopt.py to setopt.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/egg_info.py to egg_info.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/bdist_egg.py to bdist_egg.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/install_scripts.py to install_scripts.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/install_lib.py to install_lib.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/bdist_wininst.py to bdist_wininst.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/unicode_utils.py to unicode_utils.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/py31compat.py to py31compat.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/windows_support.py to windows_support.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/package_index.py to package_index.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/archive_util.py to archive_util.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/dist.py to dist.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/py27compat.py to py27compat.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/msvc9_support.py to msvc9_support.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/version.py to version.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/compat.py to compat.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/utils.py to utils.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/sandbox.py to sandbox.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/extension.py to extension.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/lib2to3_ex.py to lib2to3_ex.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/depends.py to depends.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/ssl_support.py to ssl_support.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/site-patch.py to site-patch.pyc
byte-compiling build/bdist.linux-x86_64/egg/_markerlib/markers.py to markers.pyc
byte-compiling build/bdist.linux-x86_64/egg/_markerlib/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/easy_install.py to easy_install.pyc
byte-compiling build/bdist.linux-x86_64/egg/pkg_resources/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/_structures.py to _structures.pyc
byte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/__about__.py to __about__.pyc
byte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/specifiers.py to specifiers.pyc
byte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/version.py to version.pyc
byte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/_compat.py to _compat.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
creating dist
creating 'dist/setuptools-18.2-py2.6.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing setuptools-18.2-py2.6.egg
Copying setuptools-18.2-py2.6.egg to /usr/lib/python2.6/site-packages
Adding setuptools 18.2 to easy-install.pth file
Installing easy_install script to /usr/bin
Installing easy_install-2.6 script to /usr/bin
Installed /usr/lib/python2.6/site-packages/setuptools-18.2-py2.6.egg
Processing dependencies for setuptools==18.2
Finished processing dependencies for setuptools==18.2
#
使用这种方法安装后,可以看到目录中会自动下载setuptools的软件包,也可以查看easy_install可用的命令:
# ls -la
total 888
drwxr-xr-x. 3 root root 4096 Aug 27 11:11 .
drwxr-xr-x. 12 root root 4096 Apr 15 01:16 ..
-rw-r--r-- 1 root root 11432 Aug 20 01:00 ez_setup.py
drwxr-xr-x 9 1000 1000 4096 Aug 27 11:18 psutil-2.0.0
-rw-r--r-- 1 root root 207168 May 15 01:30 psutil-2.0.0.tar.gz
-rw-r--r-- 1 root root 674659 Aug 27 10:45 setuptools-18.2.zip
# which easy_install
/usr/bin/easy_install
# easy_install --help
Global options:
--verbose (-v) run verbosely (default)
--quiet (-q) run quietly (turns verbosity off)
--dry-run (-n) don't actually do anything
--help (-h) show detailed help message
Options for 'easy_install' command:
--prefix installation prefix
--zip-ok (-z) install package as a zipfile
--multi-version (-m) make apps have to require() a version
--upgrade (-U) force upgrade (searches PyPI for latest versions)
--install-dir (-d) install package to DIR
--script-dir (-s) install scripts to DIR
--exclude-scripts (-x) Don't install scripts
--always-copy (-a) Copy all needed packages to install dir
--index-url (-i) base URL of Python Package Index
--find-links (-f) additional URL(s) to search for packages
--build-directory (-b) download/extract/build in DIR; keep the results
--optimize (-O) also compile with optimization: -O1 for "python -
O", -O2 for "python -OO", and -O0 to disable
[default: -O0]
--record filename in which to record list of installed
files
--always-unzip (-Z) don't install as a zipfile, no matter what
--site-dirs (-S) list of directories where .pth files work
--editable (-e) Install specified packages in editable fORM
--no-deps (-N) don't install dependencies
--allow-hosts (-H) pattern(s) that hostnames must match
--local-snapshots-ok (-l) allow building eggs from local checkouts
--version print version information and exit
--no-find-links Don't load find-links defined in packages being
installed
--user install in user site-package
'/root/.local/lib/python2.6/site-packages'
usage: easy_install [options] requirement_or_url ...
or: easy_install --help
二、easy_install 命令的使用方式与安装举例
setuptools安装成功后,easy_install有多种使用方法:
a、通过模块名称来安装。setuptools会自动搜索PyPI 以查找最新版本的模块。如果找到的话,她会自动下载、编译和安装:例如
easy_install sqlObject
说明,安装过程可能需要权限,如果是ubuntu的话,可以加上sudo
b、指定查找页面("download page")来使用名称和版本信息来安装或升级一个模块:
easy_install -f http://pythonpaste.org/package_index.html SQLObject
c、从指定模块下载地址来下载模块源码并在下载成功之后编译安装
easy_install http://example.com/path/to/MyPackage-1.2.3.tgz
d、在本地已经存在的egg文件基础上来安装模块
easy_install /my_downloads/OtherPackage-3.2.1-py2.3.egg
e、升级一个已经安装的模块到最新版本,如果在PyPI中这个模块有最新版本。
easy_install --upgrade PyProtocols
f、从源码中安装模块(源码已经下载并解压到当前文件夹下)(New in 0.5a9)
easy_install .
g、模块卸载 easy_install -m package-name (比如easy_install -m pylab)
如果想删除通过easy_install安装的软件包,比如说:Mysql-python,可以执行命令:
easy_install -m mysql-python
注:此操作会从easy-install.pth文件里把MySQL-python的相关信息抹去,剩下的egg文件,你可以手动删除。
上面这些具体细节可以参考easy install的官方网站:http://peak.telecommUnity.com/DevCenter/EasyInstall
例如,用第一种方法安装SQLObject模块:
# easy_install -f http://pythonpaste.org/package_index.html SQLObject
Searching for SQLObject
Reading http://pythonpaste.org/package_index.html
Reading https://pypi.python.org/simple/SQLObject/
Best match: SQLObject 3.0.0a1.dev20150327
Downloading https://pypi.python.org/packages/2.6/S/SQLObject/SQLObject-3.0.0a1dev_20150327-py2.6.egg#md5=de05545626c8c4179ebb787fb2b0cf96
Processing SQLObject-3.0.0a1dev_20150327-py2.6.egg
creating /usr/lib/python2.6/site-packages/SQLObject-3.0.0a1dev_20150327-py2.6.egg
Extracting SQLObject-3.0.0a1dev_20150327-py2.6.egg to /usr/lib/python2.6/site-packages
Adding SQLObject 3.0.0a1.dev20150327 to easy-install.pth file
Installing sqlobject-admin script to /usr/bin
Installing sqlobject-convertOldURI script to /usr/bin
Installed /usr/lib/python2.6/site-packages/SQLObject-3.0.0a1dev_20150327-py2.6.egg
Processing dependencies for SQLObject
Searching for PyDispatcher>=2.0.4
Reading https://pypi.python.org/simple/PyDispatcher/
Best match: PyDispatcher 2.0.5
Downloading https://pypi.python.org/packages/source/P/PyDispatcher/PyDispatcher-2.0.5.zip#md5=13bcd5142583a2ca4bae0664c4a235e0
Processing PyDispatcher-2.0.5.zip
Writing /tmp/easy_install-CKT2_x/PyDispatcher-2.0.5/setup.cfg
Running PyDispatcher-2.0.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-CKT2_x/PyDispatcher-2.0.5/egg-dist-tmp-wHQRh1
warning: no previously-included files matching '*.bat' found anywhere in distribution
warning: no previously-included files matching './CVS' found anywhere in distribution
warning: no previously-included files matching '.cvsignore' found anywhere in distribution
zip_safe flag not set; analyzing archive contents...
Moving PyDispatcher-2.0.5-py2.6.egg to /usr/lib/python2.6/site-packages
Adding PyDispatcher 2.0.5 to easy-install.pth file
Installed /usr/lib/python2.6/site-packages/PyDispatcher-2.0.5-py2.6.egg
Searching for FormEncode>=1.1.1
Reading https://pypi.python.org/simple/FormEncode/
Best match: FormEncode 1.3.0
Downloading https://pypi.python.org/packages/source/F/FormEncode/FormEncode-1.3.0.zip#md5=6df12d60bf3179402f2c2efd1129eb74
Processing FormEncode-1.3.0.zip
Writing /tmp/easy_install-wGGheC/FormEncode-1.3.0/setup.cfg
Running FormEncode-1.3.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-wGGheC/FormEncode-1.3.0/egg-dist-tmp-msPx0T
warning: no files found matching '*.py' under directory '.'
warning: no files found matching '*.html' under directory 'docs'
warning: no files found matching '*.py' under directory 'formencode/i18n'
warning: no previously-included files matching '*.pyc' found under directory '.'
warning: no previously-included files matching '*.pyo' found under directory '.'
warning: no previously-included files matching '*~' found under directory '.'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching '**/.svn'
no previously-included directories found matching '.hg'
no previously-included directories found matching '.git'
creating /usr/lib/python2.6/site-packages/FormEncode-1.3.0-py2.6.egg
Extracting FormEncode-1.3.0-py2.6.egg to /usr/lib/python2.6/site-packages
Adding FormEncode 1.3.0 to easy-install.pth file
Installed /usr/lib/python2.6/site-packages/FormEncode-1.3.0-py2.6.egg
Finished processing dependencies for SQLObject
这样 SQLObject模块就安装成功了。
三、以源码方式安装psutil模块
Python中的psutil模块能够获取系统运行进程和使用率,对于系统监控还是比较有意义的。
下面用easy_install以源码方式安装psutil模块:
# cd /usr/local/src
# wget https://pypi.python.org/packages/source/p/psutil/psutil-2.0.0.tar.gz --no-check-certificate
# tar -zxvf psutil-2.0.0.tar.gz
# cd psutil-2.0.0
# pwd
/usr/local/src/psutil-2.0.0
[root@centos01 psutil-2.0.0]# ll
total 128
drwxr-xr-x 4 root root 4096 Aug 27 10:57 build
-rw-r--r-- 1 1000 1000 3547 Mar 9 2014 CREDITS
drwxr-xr-x 5 1000 1000 4096 Mar 10 2014 docs
drwxr-xr-x 2 1000 1000 4096 Mar 10 2014 examples
-rw-r--r-- 1 1000 1000 31828 Mar 10 2014 HISTORY
-rw-r--r-- 1 1000 1000 1584 Mar 4 2014 LICENSE
-rw-r--r-- 1 1000 1000 5797 Mar 4 2014 make.bat
-rw-r--r-- 1 1000 1000 1593 Mar 4 2014 Makefile
-rw-r--r-- 1 1000 1000 308 Mar 4 2014 MANIFEST.in
-rw-r--r-- 1 1000 1000 13281 Mar 10 2014 PKG-INFO
drwxr-xr-x 3 1000 1000 4096 Mar 10 2014 psutil
drwxr-xr-x 2 1000 1000 4096 Mar 10 2014 psutil.egg-info
-rw-r--r-- 1 1000 1000 8740 Mar 10 2014 README
-rw-r--r-- 1 1000 1000 59 Mar 10 2014 setup.cfg
-rw-r--r-- 1 1000 1000 6488 Mar 4 2014 setup.py
drwxr-xr-x 2 1000 1000 4096 Mar 10 2014 test
-rw-r--r-- 1 1000 1000 4970 Mar 10 2014 TODO
[root@centos01 psutil-2.0.0]#
[root@centos01 psutil-2.0.0]# easy_install .
Processing .
Writing /usr/local/src/psutil-2.0.0/setup.cfg
Running setup.py -q bdist_egg --dist-dir /usr/local/src/psutil-2.0.0/egg-dist-tmp-CVh5Pq
warning: no previously-included files matching '*' found under directory 'docs/_build'
psutil/_psutil_linux.c:12:20: error: Python.h: No such file or directory
In file included from psutil/_psutil_linux.c:23:
psutil/_psutil_linux.h:11: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
psutil/_psutil_linux.h:12: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
psutil/_psutil_linux.h:13: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
psutil/_psutil_linux.h:14: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
psutil/_psutil_linux.h:18: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
psutil/_psutil_linux.h:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
psutil/_psutil_linux.h:20: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
psutil/_psutil_linux.c: In function ‘ioprio_get’:
psutil/_psutil_linux.c:50: warning: implicit declaration of function ‘syscall’
psutil/_psutil_linux.c: At top level:
psutil/_psutil_linux.c:70: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
psutil/_psutil_linux.c:93: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
psutil/_psutil_linux.c:181: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
psutil/_psutil_linux.c:232: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
psutil/_psutil_linux.c:255: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
psutil/_psutil_linux.c:275: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
psutil/_psutil_linux.c:336: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
psutil/_psutil_linux.c:384: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PsutilMethods’
psutil/_psutil_linux.c:421: error: expected specifier-qualifier-list before ‘PyObject’
psutil/_psutil_linux.c: In function ‘init_psutil_linux’:
psutil/_psutil_linux.c:470: error: ‘PyObject’ undeclared (first use in this function)
psutil/_psutil_linux.c:470: error: (Each undeclared identifier is reported only once
psutil/_psutil_linux.c:470: error: for each function it appears in.)
psutil/_psutil_linux.c:470: error: ‘module’ undeclared (first use in this function)
psutil/_psutil_linux.c:470: warning: implicit declaration of function ‘Py_InitModule’
psutil/_psutil_linux.c:470: error: ‘PsutilMethods’ undeclared (first use in this function)
error: Setup script exited with error: command 'GCc' failed with exit status 1
使用easy_install进行源码安装时,可能会有如下报错:用安装python模块出现error: command 'gcc' failed with exit status 1 ,明明装了gcc的,怎么会不行呢,然后发觉是failed不是not found,这说明这个错误个gcc没多 大关系,应该是缺少某些功能模块,然后谷歌了一下,先后安装了python-devel,libffi-devel后还是不行,最后发觉要安装openssl-devel才行,可如下命令行安装:
yum install gcc libffi-devel python-devel openssl-devel
过程如下:
# yum install gcc libffi-devel python-devel openssl-devel
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirror.bit.edu.cn
* extras: mirrors.btte.net
* updates: mirrors.btte.net
Setting up Install Process
Package gcc-4.4.7-16.el6.x86_64 already installed and latest version
Package libffi-devel-3.0.5-3.2.el6.x86_64 already installed and latest version
Package openssl-devel-1.0.1e-42.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package python-devel.x86_64 0:2.6.6-64.el6 will be installed
--> Processing Dependency: python-libs(x86-64) = 2.6.6-64.el6 for package: python-devel-2.6.6-64.el6.x86_64
--> Processing Dependency: python = 2.6.6-64.el6 for package: python-devel-2.6.6-64.el6.x86_64
--> Running transaction check
---> Package python.x86_64 0:2.6.6-51.el6 will be updated
---> Package python.x86_64 0:2.6.6-64.el6 will be an update
---> Package python-libs.x86_64 0:2.6.6-51.el6 will be updated
---> Package python-libs.x86_64 0:2.6.6-64.el6 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================
Package Arch Version Repository Size
=============================================================================================================
Installing:
python-devel x86_64 2.6.6-64.el6 base 172 k
Updating for dependencies:
python x86_64 2.6.6-64.el6 base 76 k
python-libs x86_64 2.6.6-64.el6 base 5.3 M
Transaction Summary
=============================================================================================================
Install 1 Package(s)
Upgrade 2 Package(s)
Total download size: 5.6 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): python-2.6.6-64.el6.x86_64.rpm | 76 kB 00:00
(2/3): python-devel-2.6.6-64.el6.x86_64.rpm | 172 kB 00:00
(3/3): python-libs-2.6.6-64.el6.x86_64.rpm | 5.3 MB 00:17
-------------------------------------------------------------------------------------------------------------
Total 317 kB/s | 5.6 MB 00:17
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : python-2.6.6-64.el6.x86_64 1/5
Updating : python-libs-2.6.6-64.el6.x86_64 2/5
Installing : python-devel-2.6.6-64.el6.x86_64 3/5
Cleanup : python-2.6.6-51.el6.x86_64 4/5
Cleanup : python-libs-2.6.6-51.el6.x86_64 5/5
Verifying : python-devel-2.6.6-64.el6.x86_64 1/5
Verifying : python-libs-2.6.6-64.el6.x86_64 2/5
Verifying : python-2.6.6-64.el6.x86_64 3/5
Verifying : python-libs-2.6.6-51.el6.x86_64 4/5
Verifying : python-2.6.6-51.el6.x86_64 5/5
Installed:
python-devel.x86_64 0:2.6.6-64.el6
Dependency Updated:
python.x86_64 0:2.6.6-64.el6 python-libs.x86_64 0:2.6.6-64.el6
Complete!
再次安装,就可以正常安装psutil模块了:
# easy_install .
Processing .
Writing /usr/local/src/psutil-2.0.0/setup.cfg
Running setup.py -q bdist_egg --dist-dir /usr/local/src/psutil-2.0.0/egg-dist-tmp-wshhD1
warning: no previously-included files matching '*' found under directory 'docs/_build'
psutil/_psutil_linux.c: In function ‘psutil_proc_cpu_affinity_set’:
psutil/_psutil_linux.c:327: warning: suggest explicit braces to avoid ambiguous ‘else’
zip_safe flag not set; analyzing archive contents...
Moving psutil-2.0.0-py2.6-linux-x86_64.egg to /usr/lib/python2.6/site-packages
Adding psutil 2.0.0 to easy-install.pth file
Installed /usr/lib/python2.6/site-packages/psutil-2.0.0-py2.6-linux-x86_64.egg
Processing dependencies for psutil==2.0.0
Finished processing dependencies for psutil==2.0.0
psutil模块安装完毕后,可以在Python终端中调用各种命令来获取系统状态:
# python
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 psutil
/usr/lib/python2.6/site-packages/psutil-2.0.0-py2.6-linux-x86_64.egg/_psutil_linux.py:3: UserWarning: Module _psutil_linux was already imported from
/usr/lib/python2.6/site-packages/psutil-2.0.0-py2.6-linux-x86_64.egg/_psutil_linux.pyc, but /usr/local/src/psutil-2.0.0 is being added to sys.path
>>> psutil.cpu_times()
scputimes(user=43.100000000000001, nice=0.0, system=36.119999999999997, idle=10653.4, iowait=285.0, irq=1.0600000000000001, softirq=3.1000000000000001,
steal=0.0, guest=0.0)
>>> psutil.cpu_times().user
43.130000000000003
>>> psutil.cpu_count()
4
>>> psutil.cpu_count(logical=False)
2
>>> mem = psutil.virtual_memory()
>>> mem
svmem(total=1036648448L, available=733806592L, percent=29.199999999999999, used=888340480L, free=148307968L, active=244699136, inactive=500060160,
buffers=47853568L, cached=537645056)
>>> mem.total
1036648448L
>>> mem.free
148307968L
>>> psutil.swap_memory()
sswap(total=2080366592L, used=8192L, free=2080358400L, percent=0.0, sin=0, sout=0)
>>>
>>> psutil.disk_partition()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'ModuleWrapper' object has no attribute 'disk_partition'
>>> psutil.disk_partitions()
[sdiskpart(device='/dev/mapper/vg_centos01-lv_root', mountpoint='/', fstype='ext4', opts='rw'), sdiskpart(device='/dev/sda1', mountpoint='/boot',
fstype='ext4', opts='rw')]
>>>
>>> psutil.disk_usage('/')
sdiskusage(total=18569568256, used=4755951616, free=12870320128, percent=25.600000000000001)
>>> psutil.disk_io_counters()
sdiskio(read_count=37622, write_count=230886, read_bytes=688139264, write_bytes=1625135104, read_time=664928, write_time=22065267)
>>>
>>> psutil.disk_io_counters(perdisk=True)
{'dm-1': sdiskio(read_count=322, write_count=0, read_bytes=1318912, write_bytes=0, read_time=653, write_time=0), 'sda2': sdiskio(read_count=14739,
write_count=32509, read_bytes=343094272, write_bytes=812621824, read_time=282044, write_time=1616651), 'dm-0': sdiskio(read_count=21964,
write_count=198394, read_bytes=341320704, write_bytes=812621824, read_time=382104, write_time=20448581), 'sda1': sdiskio(read_count=597, write_count=7,
read_bytes=2405376, write_bytes=14336, read_time=127, write_time=93)}
>>>
>>> psutil.net_io_counters()
snetio(bytes_sent=3186898, bytes_recv=119382022, packets_sent=43509, packets_recv=84308, errin=0, errout=0, dropin=0, dropout=0)
>>>
>>> psutil.net_io_counters(pernic=True)
{'lo': snetio(bytes_sent=960, bytes_recv=960, packets_sent=16, packets_recv=16, errin=0, errout=0, dropin=0, dropout=0), 'eth0': snetio
(bytes_sent=3192258, bytes_recv=119388892, packets_sent=43535, packets_recv=84361, errin=0, errout=0, dropin=0, dropout=0)}
>>>
>>> psutil.users()
[suser(name='root', terminal='tty1', host=':0', started=1440643328.0), suser(name='root', terminal='pts/0', host='localhost', started=1440643328.0),
suser(name='root', terminal='pts/1', host='192.168.226.1', started=1440643328.0)]
>>> import psutil,datetime
>>>
>>> psutil.boot_time()
1440642945.0
>>>
>>> datetime.datetime.fromtimestamp(psutil.boot_time()).strftime("%Y-%m-%d %H:%M:%S")
'2015-08-27 10:35:45'
>>>
相关文章