python setuptools安装与psutil模块测试

来源:互联网 发布:网络推广标准工作计划 编辑:程序博客网 时间:2024/05/02 23:52


         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.pyResolving bootstrap.pypa.io... 103.245.222.175Connecting 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 OKLength: 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 --insecureDownloading https://pypi.python.org/packages/source/s/setuptools/setuptools-18.2.zipExtracting in /tmp/tmpn65Wy1Now working in /tmp/tmpn65Wy1/setuptools-18.2Installing Setuptoolsrunning installrunning bdist_eggrunning egg_infowriting requirements to setuptools.egg-info/requires.txtwriting setuptools.egg-info/PKG-INFOwriting top-level names to setuptools.egg-info/top_level.txtwriting dependency_links to setuptools.egg-info/dependency_links.txtwriting entry points to setuptools.egg-info/entry_points.txtwriting requirements to setuptools.egg-info/requires.txtwriting setuptools.egg-info/PKG-INFOwriting top-level names to setuptools.egg-info/top_level.txtwriting dependency_links to setuptools.egg-info/dependency_links.txtwriting entry points to setuptools.egg-info/entry_points.txtreading 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/eggrunning install_librunning build_pycreating buildcreating build/libcopying easy_install.py -> build/libcreating build/lib/setuptoolscopying setuptools/py26compat.py -> build/lib/setuptoolscopying setuptools/unicode_utils.py -> build/lib/setuptoolscopying setuptools/py31compat.py -> build/lib/setuptoolscopying setuptools/windows_support.py -> build/lib/setuptoolscopying setuptools/package_index.py -> build/lib/setuptoolscopying setuptools/archive_util.py -> build/lib/setuptoolscopying setuptools/dist.py -> build/lib/setuptoolscopying setuptools/py27compat.py -> build/lib/setuptoolscopying setuptools/msvc9_support.py -> build/lib/setuptoolscopying setuptools/version.py -> build/lib/setuptoolscopying setuptools/compat.py -> build/lib/setuptoolscopying setuptools/__init__.py -> build/lib/setuptoolscopying setuptools/utils.py -> build/lib/setuptoolscopying setuptools/sandbox.py -> build/lib/setuptoolscopying setuptools/extension.py -> build/lib/setuptoolscopying setuptools/lib2to3_ex.py -> build/lib/setuptoolscopying setuptools/depends.py -> build/lib/setuptoolscopying setuptools/ssl_support.py -> build/lib/setuptoolscopying setuptools/site-patch.py -> build/lib/setuptoolscreating build/lib/_markerlibcopying _markerlib/markers.py -> build/lib/_markerlibcopying _markerlib/__init__.py -> build/lib/_markerlibcreating build/lib/pkg_resourcescopying pkg_resources/__init__.py -> build/lib/pkg_resourcescreating build/lib/setuptools/commandcopying setuptools/command/bdist_rpm.py -> build/lib/setuptools/commandcopying setuptools/command/develop.py -> build/lib/setuptools/commandcopying setuptools/command/build_ext.py -> build/lib/setuptools/commandcopying setuptools/command/install.py -> build/lib/setuptools/commandcopying setuptools/command/upload_docs.py -> build/lib/setuptools/commandcopying setuptools/command/register.py -> build/lib/setuptools/commandcopying setuptools/command/build_py.py -> build/lib/setuptools/commandcopying setuptools/command/saveopts.py -> build/lib/setuptools/commandcopying setuptools/command/alias.py -> build/lib/setuptools/commandcopying setuptools/command/install_egg_info.py -> build/lib/setuptools/commandcopying setuptools/command/__init__.py -> build/lib/setuptools/commandcopying setuptools/command/test.py -> build/lib/setuptools/commandcopying setuptools/command/easy_install.py -> build/lib/setuptools/commandcopying setuptools/command/rotate.py -> build/lib/setuptools/commandcopying setuptools/command/sdist.py -> build/lib/setuptools/commandcopying setuptools/command/setopt.py -> build/lib/setuptools/commandcopying setuptools/command/egg_info.py -> build/lib/setuptools/commandcopying setuptools/command/bdist_egg.py -> build/lib/setuptools/commandcopying setuptools/command/install_scripts.py -> build/lib/setuptools/commandcopying setuptools/command/install_lib.py -> build/lib/setuptools/commandcopying setuptools/command/bdist_wininst.py -> build/lib/setuptools/commandcreating build/lib/pkg_resources/_vendorcopying pkg_resources/_vendor/__init__.py -> build/lib/pkg_resources/_vendorcreating build/lib/pkg_resources/_vendor/packagingcopying pkg_resources/_vendor/packaging/_structures.py -> build/lib/pkg_resources/_vendor/packagingcopying pkg_resources/_vendor/packaging/__about__.py -> build/lib/pkg_resources/_vendor/packagingcopying pkg_resources/_vendor/packaging/specifiers.py -> build/lib/pkg_resources/_vendor/packagingcopying pkg_resources/_vendor/packaging/version.py -> build/lib/pkg_resources/_vendor/packagingcopying pkg_resources/_vendor/packaging/__init__.py -> build/lib/pkg_resources/_vendor/packagingcopying pkg_resources/_vendor/packaging/_compat.py -> build/lib/pkg_resources/_vendor/packagingcopying setuptools/script (dev).tmpl -> build/lib/setuptoolscopying setuptools/script.tmpl -> build/lib/setuptoolscreating build/bdist.linux-x86_64creating build/bdist.linux-x86_64/eggcreating build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/py26compat.py -> build/bdist.linux-x86_64/egg/setuptoolscreating build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/bdist_rpm.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/develop.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/build_ext.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/install.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/upload_docs.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/register.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/build_py.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/saveopts.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/alias.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/install_egg_info.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/__init__.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/test.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/easy_install.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/rotate.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/sdist.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/setopt.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/egg_info.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/bdist_egg.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/install_scripts.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/install_lib.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/command/bdist_wininst.py -> build/bdist.linux-x86_64/egg/setuptools/commandcopying build/lib/setuptools/unicode_utils.py -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/py31compat.py -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/windows_support.py -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/script.tmpl -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/package_index.py -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/archive_util.py -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/dist.py -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/script (dev).tmpl -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/py27compat.py -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/msvc9_support.py -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/version.py -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/compat.py -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/__init__.py -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/utils.py -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/sandbox.py -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/extension.py -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/lib2to3_ex.py -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/depends.py -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/ssl_support.py -> build/bdist.linux-x86_64/egg/setuptoolscopying build/lib/setuptools/site-patch.py -> build/bdist.linux-x86_64/egg/setuptoolscreating build/bdist.linux-x86_64/egg/_markerlibcopying build/lib/_markerlib/markers.py -> build/bdist.linux-x86_64/egg/_markerlibcopying build/lib/_markerlib/__init__.py -> build/bdist.linux-x86_64/egg/_markerlibcopying build/lib/easy_install.py -> build/bdist.linux-x86_64/eggcreating build/bdist.linux-x86_64/egg/pkg_resourcescopying build/lib/pkg_resources/__init__.py -> build/bdist.linux-x86_64/egg/pkg_resourcescreating build/bdist.linux-x86_64/egg/pkg_resources/_vendorcopying build/lib/pkg_resources/_vendor/__init__.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendorcreating build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packagingcopying build/lib/pkg_resources/_vendor/packaging/_structures.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packagingcopying build/lib/pkg_resources/_vendor/packaging/__about__.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packagingcopying build/lib/pkg_resources/_vendor/packaging/specifiers.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packagingcopying build/lib/pkg_resources/_vendor/packaging/version.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packagingcopying build/lib/pkg_resources/_vendor/packaging/__init__.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packagingcopying build/lib/pkg_resources/_vendor/packaging/_compat.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packagingbyte-compiling build/bdist.linux-x86_64/egg/setuptools/py26compat.py to py26compat.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/bdist_rpm.py to bdist_rpm.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/develop.py to develop.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/build_ext.py to build_ext.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/install.py to install.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/upload_docs.py to upload_docs.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/register.py to register.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/build_py.py to build_py.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/saveopts.py to saveopts.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/alias.py to alias.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/install_egg_info.py to install_egg_info.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/__init__.py to __init__.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/test.py to test.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py to easy_install.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/rotate.py to rotate.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/sdist.py to sdist.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/setopt.py to setopt.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/egg_info.py to egg_info.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/bdist_egg.py to bdist_egg.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/install_scripts.py to install_scripts.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/install_lib.py to install_lib.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/command/bdist_wininst.py to bdist_wininst.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/unicode_utils.py to unicode_utils.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/py31compat.py to py31compat.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/windows_support.py to windows_support.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/package_index.py to package_index.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/archive_util.py to archive_util.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/dist.py to dist.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/py27compat.py to py27compat.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/msvc9_support.py to msvc9_support.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/version.py to version.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/compat.py to compat.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/__init__.py to __init__.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/utils.py to utils.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/sandbox.py to sandbox.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/extension.py to extension.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/lib2to3_ex.py to lib2to3_ex.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/depends.py to depends.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/ssl_support.py to ssl_support.pycbyte-compiling build/bdist.linux-x86_64/egg/setuptools/site-patch.py to site-patch.pycbyte-compiling build/bdist.linux-x86_64/egg/_markerlib/markers.py to markers.pycbyte-compiling build/bdist.linux-x86_64/egg/_markerlib/__init__.py to __init__.pycbyte-compiling build/bdist.linux-x86_64/egg/easy_install.py to easy_install.pycbyte-compiling build/bdist.linux-x86_64/egg/pkg_resources/__init__.py to __init__.pycbyte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/__init__.py to __init__.pycbyte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/_structures.py to _structures.pycbyte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/__about__.py to __about__.pycbyte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/specifiers.py to specifiers.pycbyte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/version.py to version.pycbyte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/__init__.py to __init__.pycbyte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/_compat.py to _compat.pyccreating build/bdist.linux-x86_64/egg/EGG-INFOcopying setuptools.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFOcopying setuptools.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFOcopying setuptools.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFOcopying setuptools.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFOcopying setuptools.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFOcopying setuptools.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFOcopying setuptools.egg-info/zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFOcreating distcreating 'dist/setuptools-18.2-py2.6.egg' and adding 'build/bdist.linux-x86_64/egg' to itremoving 'build/bdist.linux-x86_64/egg' (and everything under it)Processing setuptools-18.2-py2.6.eggCopying setuptools-18.2-py2.6.egg to /usr/lib/python2.6/site-packagesAdding setuptools 18.2 to easy-install.pth fileInstalling easy_install script to /usr/binInstalling easy_install-2.6 script to /usr/binInstalled /usr/lib/python2.6/site-packages/setuptools-18.2-py2.6.eggProcessing dependencies for setuptools==18.2Finished processing dependencies for setuptools==18.2# 



         使用这种方法安装后,可以看到目录中会自动下载setuptools的软件包,也可以查看easy_install可用的命令:

# ls -latotal 888drwxr-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.pydrwxr-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 --helpGlobal 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 messageOptions 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 SQLObjectSearching for SQLObjectReading http://pythonpaste.org/package_index.htmlReading https://pypi.python.org/simple/SQLObject/Best match: SQLObject 3.0.0a1.dev20150327Downloading https://pypi.python.org/packages/2.6/S/SQLObject/SQLObject-3.0.0a1dev_20150327-py2.6.egg#md5=de05545626c8c4179ebb787fb2b0cf96Processing SQLObject-3.0.0a1dev_20150327-py2.6.eggcreating /usr/lib/python2.6/site-packages/SQLObject-3.0.0a1dev_20150327-py2.6.eggExtracting SQLObject-3.0.0a1dev_20150327-py2.6.egg to /usr/lib/python2.6/site-packagesAdding SQLObject 3.0.0a1.dev20150327 to easy-install.pth fileInstalling sqlobject-admin script to /usr/binInstalling sqlobject-convertOldURI script to /usr/binInstalled /usr/lib/python2.6/site-packages/SQLObject-3.0.0a1dev_20150327-py2.6.eggProcessing dependencies for SQLObjectSearching for PyDispatcher>=2.0.4Reading https://pypi.python.org/simple/PyDispatcher/Best match: PyDispatcher 2.0.5Downloading https://pypi.python.org/packages/source/P/PyDispatcher/PyDispatcher-2.0.5.zip#md5=13bcd5142583a2ca4bae0664c4a235e0Processing PyDispatcher-2.0.5.zipWriting /tmp/easy_install-CKT2_x/PyDispatcher-2.0.5/setup.cfgRunning PyDispatcher-2.0.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-CKT2_x/PyDispatcher-2.0.5/egg-dist-tmp-wHQRh1warning: no previously-included files matching '*.bat' found anywhere in distributionwarning: no previously-included files matching './CVS' found anywhere in distributionwarning: no previously-included files matching '.cvsignore' found anywhere in distributionzip_safe flag not set; analyzing archive contents...Moving PyDispatcher-2.0.5-py2.6.egg to /usr/lib/python2.6/site-packagesAdding PyDispatcher 2.0.5 to easy-install.pth fileInstalled /usr/lib/python2.6/site-packages/PyDispatcher-2.0.5-py2.6.eggSearching for FormEncode>=1.1.1Reading https://pypi.python.org/simple/FormEncode/Best match: FormEncode 1.3.0Downloading https://pypi.python.org/packages/source/F/FormEncode/FormEncode-1.3.0.zip#md5=6df12d60bf3179402f2c2efd1129eb74Processing FormEncode-1.3.0.zipWriting /tmp/easy_install-wGGheC/FormEncode-1.3.0/setup.cfgRunning FormEncode-1.3.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-wGGheC/FormEncode-1.3.0/egg-dist-tmp-msPx0Twarning: 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.eggExtracting FormEncode-1.3.0-py2.6.egg to /usr/lib/python2.6/site-packagesAdding FormEncode 1.3.0 to easy-install.pth fileInstalled /usr/lib/python2.6/site-packages/FormEncode-1.3.0-py2.6.eggFinished 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]# lltotal 128drwxr-xr-x 4 root root  4096 Aug 27 10:57 build-rw-r--r-- 1 1000 1000  3547 Mar  9  2014 CREDITSdrwxr-xr-x 5 1000 1000  4096 Mar 10  2014 docsdrwxr-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-INFOdrwxr-xr-x 3 1000 1000  4096 Mar 10  2014 psutildrwxr-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.pydrwxr-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.cfgRunning setup.py -q bdist_egg --dist-dir /usr/local/src/psutil-2.0.0/egg-dist-tmp-CVh5Pqwarning: no previously-included files matching '*' found under directory 'docs/_build'psutil/_psutil_linux.c:12:20: error: Python.h: No such file or directoryIn file included from psutil/_psutil_linux.c:23:psutil/_psutil_linux.h:11: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ tokenpsutil/_psutil_linux.h:12: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ tokenpsutil/_psutil_linux.h:13: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ tokenpsutil/_psutil_linux.h:14: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ tokenpsutil/_psutil_linux.h:18: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ tokenpsutil/_psutil_linux.h:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ tokenpsutil/_psutil_linux.h:20: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ tokenpsutil/_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 ‘*’ tokenpsutil/_psutil_linux.c:93: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ tokenpsutil/_psutil_linux.c:181: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ tokenpsutil/_psutil_linux.c:232: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ tokenpsutil/_psutil_linux.c:255: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ tokenpsutil/_psutil_linux.c:275: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ tokenpsutil/_psutil_linux.c:336: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ tokenpsutil/_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 oncepsutil/_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-develLoaded plugins: fastestmirror, refresh-packagekit, securityLoading mirror speeds from cached hostfile * base: mirror.bit.edu.cn * extras: mirrors.btte.net * updates: mirrors.btte.netSetting up Install ProcessPackage gcc-4.4.7-16.el6.x86_64 already installed and latest versionPackage libffi-devel-3.0.5-3.2.el6.x86_64 already installed and latest versionPackage openssl-devel-1.0.1e-42.el6.x86_64 already installed and latest versionResolving 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 ResolutionDependencies Resolved============================================================================================================= Package                      Arch                   Version                      Repository            Size=============================================================================================================Installing: python-devel                 x86_64                 2.6.6-64.el6                 base                 172 kUpdating 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 MTransaction Summary=============================================================================================================Install       1 Package(s)Upgrade       2 Package(s)Total download size: 5.6 MIs this ok [y/N]: yDownloading 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_debugRunning Transaction TestTransaction Test SucceededRunning 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!


         再次执行easy_install 安装命令:

# easy_install .Processing .Writing /usr/local/src/psutil-2.0.0/setup.cfgRunning setup.py -q bdist_egg --dist-dir /usr/local/src/psutil-2.0.0/egg-dist-tmp-wshhD1warning: 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-packagesAdding psutil 2.0.0 to easy-install.pth fileInstalled /usr/lib/python2.6/site-packages/psutil-2.0.0-py2.6-linux-x86_64.eggProcessing dependencies for psutil==2.0.0Finished processing dependencies for psutil==2.0.0


          psutil模块安装完毕后,可以在Python终端中调用各种命令来获取系统状态:

# pythonPython 2.6.6 (r266:84292, Jul 23 2015, 15:22:56) [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2Type "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().user43.130000000000003>>> psutil.cpu_count()4>>> psutil.cpu_count(logical=False)2>>> mem = psutil.virtual_memory()>>> memsvmem(total=1036648448L, available=733806592L, percent=29.199999999999999, used=888340480L, free=148307968L, active=244699136, inactive=500060160,  buffers=47853568L, cached=537645056)>>> mem.total1036648448L>>> mem.free148307968L>>> 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'>>> 



0 0