python setuptools安装与psutil模块测试

ゝ一纸荒年。 2022-08-04 12:40 309阅读 0赞



  1. Python本身自带了一套工具distutils ,用于发布 Python 应用程序。但 distutils 没有提供定义其它依赖包的功能,setuptools 的真正优点并不在于实现distutils 所能实现的功能——尽管它的确增强了distutils的功能并简化了setup.py 脚本中的内容。setuptools 最大的优势是它在包管理能力方面的增强。它可以使用一种更加透明的方法来查找、下载并安装依赖包;并可以在一个包的多个版本中自由进行切换,这些版本都安装在同一个系统上;也可以声明对某个包的特定版本的需求;还可以只使用一个简单的命令就能更新到某个包的最新版本。
  2. 简单来说,Python setuptools可以看做是增强版的distutils,用来管理Python的各种包。
  3. 一般在CentOS系统安装完成后,Python编译器就已经会安装好了,对于setuptools工具的安装,可以用ea\_setup.py脚本的方法,自动下载安装包并安装;也可以先下载完整的setuptools安装包,然后再单独安装。

一、以ez_setup.py脚本方式安装setuptools工具

  1. 使用ez\_setup.py脚本的方法比较简单,但要注意服务器要能够联网下载软件包,安装命令为:

# cd /usr/local/src/
# wget —no-check-certificate https://bootstrap.pypa.io/ez_setup.py
# python ez_setup.py —insecure

  1. 安装的过程为:
  2. # wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py
  3. --2015-08-27 10:43:48-- https://bootstrap.pypa.io/ez_setup.py
  4. Resolving bootstrap.pypa.io... 103.245.222.175
  5. Connecting to bootstrap.pypa.io|103.245.222.175|:443... connected.
  6. WARNING: certificate common name “*.c.ssl.fastly.net doesnt match requested host name bootstrap.pypa.io”.
  7. HTTP request sent, awaiting response... 200 OK
  8. Length: 11432 (11K) [text/x-python]
  9. Saving to: ez_setup.py
  10. 100%[===================================================================>] 11,432 --.-K/s in 0s
  11. 2015-08-27 10:43:49 (692 MB/s) - ez_setup.py saved [11432/11432]
  12. #
  13. # python ez_setup.py --insecure
  14. Downloading https://pypi.python.org/packages/source/s/setuptools/setuptools-18.2.zip
  15. Extracting in /tmp/tmpn65Wy1
  16. Now working in /tmp/tmpn65Wy1/setuptools-18.2
  17. Installing Setuptools
  18. running install
  19. running bdist_egg
  20. running egg_info
  21. writing requirements to setuptools.egg-info/requires.txt
  22. writing setuptools.egg-info/PKG-INFO
  23. writing top-level names to setuptools.egg-info/top_level.txt
  24. writing dependency_links to setuptools.egg-info/dependency_links.txt
  25. writing entry points to setuptools.egg-info/entry_points.txt
  26. writing requirements to setuptools.egg-info/requires.txt
  27. writing setuptools.egg-info/PKG-INFO
  28. writing top-level names to setuptools.egg-info/top_level.txt
  29. writing dependency_links to setuptools.egg-info/dependency_links.txt
  30. writing entry points to setuptools.egg-info/entry_points.txt
  31. reading manifest file 'setuptools.egg-info/SOURCES.txt'
  32. reading manifest template 'MANIFEST.in'
  33. writing manifest file 'setuptools.egg-info/SOURCES.txt'
  34. installing library code to build/bdist.linux-x86_64/egg
  35. running install_lib
  36. running build_py
  37. creating build
  38. creating build/lib
  39. copying easy_install.py -> build/lib
  40. creating build/lib/setuptools
  41. copying setuptools/py26compat.py -> build/lib/setuptools
  42. copying setuptools/unicode_utils.py -> build/lib/setuptools
  43. copying setuptools/py31compat.py -> build/lib/setuptools
  44. copying setuptools/windows_support.py -> build/lib/setuptools
  45. copying setuptools/package_index.py -> build/lib/setuptools
  46. copying setuptools/archive_util.py -> build/lib/setuptools
  47. copying setuptools/dist.py -> build/lib/setuptools
  48. copying setuptools/py27compat.py -> build/lib/setuptools
  49. copying setuptools/msvc9_support.py -> build/lib/setuptools
  50. copying setuptools/version.py -> build/lib/setuptools
  51. copying setuptools/compat.py -> build/lib/setuptools
  52. copying setuptools/__init__.py -> build/lib/setuptools
  53. copying setuptools/utils.py -> build/lib/setuptools
  54. copying setuptools/sandbox.py -> build/lib/setuptools
  55. copying setuptools/extension.py -> build/lib/setuptools
  56. copying setuptools/lib2to3_ex.py -> build/lib/setuptools
  57. copying setuptools/depends.py -> build/lib/setuptools
  58. copying setuptools/ssl_support.py -> build/lib/setuptools
  59. copying setuptools/site-patch.py -> build/lib/setuptools
  60. creating build/lib/_markerlib
  61. copying _markerlib/markers.py -> build/lib/_markerlib
  62. copying _markerlib/__init__.py -> build/lib/_markerlib
  63. creating build/lib/pkg_resources
  64. copying pkg_resources/__init__.py -> build/lib/pkg_resources
  65. creating build/lib/setuptools/command
  66. copying setuptools/command/bdist_rpm.py -> build/lib/setuptools/command
  67. copying setuptools/command/develop.py -> build/lib/setuptools/command
  68. copying setuptools/command/build_ext.py -> build/lib/setuptools/command
  69. copying setuptools/command/install.py -> build/lib/setuptools/command
  70. copying setuptools/command/upload_docs.py -> build/lib/setuptools/command
  71. copying setuptools/command/register.py -> build/lib/setuptools/command
  72. copying setuptools/command/build_py.py -> build/lib/setuptools/command
  73. copying setuptools/command/saveopts.py -> build/lib/setuptools/command
  74. copying setuptools/command/alias.py -> build/lib/setuptools/command
  75. copying setuptools/command/install_egg_info.py -> build/lib/setuptools/command
  76. copying setuptools/command/__init__.py -> build/lib/setuptools/command
  77. copying setuptools/command/test.py -> build/lib/setuptools/command
  78. copying setuptools/command/easy_install.py -> build/lib/setuptools/command
  79. copying setuptools/command/rotate.py -> build/lib/setuptools/command
  80. copying setuptools/command/sdist.py -> build/lib/setuptools/command
  81. copying setuptools/command/setopt.py -> build/lib/setuptools/command
  82. copying setuptools/command/egg_info.py -> build/lib/setuptools/command
  83. copying setuptools/command/bdist_egg.py -> build/lib/setuptools/command
  84. copying setuptools/command/install_scripts.py -> build/lib/setuptools/command
  85. copying setuptools/command/install_lib.py -> build/lib/setuptools/command
  86. copying setuptools/command/bdist_wininst.py -> build/lib/setuptools/command
  87. creating build/lib/pkg_resources/_vendor
  88. copying pkg_resources/_vendor/__init__.py -> build/lib/pkg_resources/_vendor
  89. creating build/lib/pkg_resources/_vendor/packaging
  90. copying pkg_resources/_vendor/packaging/_structures.py -> build/lib/pkg_resources/_vendor/packaging
  91. copying pkg_resources/_vendor/packaging/__about__.py -> build/lib/pkg_resources/_vendor/packaging
  92. copying pkg_resources/_vendor/packaging/specifiers.py -> build/lib/pkg_resources/_vendor/packaging
  93. copying pkg_resources/_vendor/packaging/version.py -> build/lib/pkg_resources/_vendor/packaging
  94. copying pkg_resources/_vendor/packaging/__init__.py -> build/lib/pkg_resources/_vendor/packaging
  95. copying pkg_resources/_vendor/packaging/_compat.py -> build/lib/pkg_resources/_vendor/packaging
  96. copying setuptools/script (dev).tmpl -> build/lib/setuptools
  97. copying setuptools/script.tmpl -> build/lib/setuptools
  98. creating build/bdist.linux-x86_64
  99. creating build/bdist.linux-x86_64/egg
  100. creating build/bdist.linux-x86_64/egg/setuptools
  101. copying build/lib/setuptools/py26compat.py -> build/bdist.linux-x86_64/egg/setuptools
  102. creating build/bdist.linux-x86_64/egg/setuptools/command
  103. copying build/lib/setuptools/command/bdist_rpm.py -> build/bdist.linux-x86_64/egg/setuptools/command
  104. copying build/lib/setuptools/command/develop.py -> build/bdist.linux-x86_64/egg/setuptools/command
  105. copying build/lib/setuptools/command/build_ext.py -> build/bdist.linux-x86_64/egg/setuptools/command
  106. copying build/lib/setuptools/command/install.py -> build/bdist.linux-x86_64/egg/setuptools/command
  107. copying build/lib/setuptools/command/upload_docs.py -> build/bdist.linux-x86_64/egg/setuptools/command
  108. copying build/lib/setuptools/command/register.py -> build/bdist.linux-x86_64/egg/setuptools/command
  109. copying build/lib/setuptools/command/build_py.py -> build/bdist.linux-x86_64/egg/setuptools/command
  110. copying build/lib/setuptools/command/saveopts.py -> build/bdist.linux-x86_64/egg/setuptools/command
  111. copying build/lib/setuptools/command/alias.py -> build/bdist.linux-x86_64/egg/setuptools/command
  112. copying build/lib/setuptools/command/install_egg_info.py -> build/bdist.linux-x86_64/egg/setuptools/command
  113. copying build/lib/setuptools/command/__init__.py -> build/bdist.linux-x86_64/egg/setuptools/command
  114. copying build/lib/setuptools/command/test.py -> build/bdist.linux-x86_64/egg/setuptools/command
  115. copying build/lib/setuptools/command/easy_install.py -> build/bdist.linux-x86_64/egg/setuptools/command
  116. copying build/lib/setuptools/command/rotate.py -> build/bdist.linux-x86_64/egg/setuptools/command
  117. copying build/lib/setuptools/command/sdist.py -> build/bdist.linux-x86_64/egg/setuptools/command
  118. copying build/lib/setuptools/command/setopt.py -> build/bdist.linux-x86_64/egg/setuptools/command
  119. copying build/lib/setuptools/command/egg_info.py -> build/bdist.linux-x86_64/egg/setuptools/command
  120. copying build/lib/setuptools/command/bdist_egg.py -> build/bdist.linux-x86_64/egg/setuptools/command
  121. copying build/lib/setuptools/command/install_scripts.py -> build/bdist.linux-x86_64/egg/setuptools/command
  122. copying build/lib/setuptools/command/install_lib.py -> build/bdist.linux-x86_64/egg/setuptools/command
  123. copying build/lib/setuptools/command/bdist_wininst.py -> build/bdist.linux-x86_64/egg/setuptools/command
  124. copying build/lib/setuptools/unicode_utils.py -> build/bdist.linux-x86_64/egg/setuptools
  125. copying build/lib/setuptools/py31compat.py -> build/bdist.linux-x86_64/egg/setuptools
  126. copying build/lib/setuptools/windows_support.py -> build/bdist.linux-x86_64/egg/setuptools
  127. copying build/lib/setuptools/script.tmpl -> build/bdist.linux-x86_64/egg/setuptools
  128. copying build/lib/setuptools/package_index.py -> build/bdist.linux-x86_64/egg/setuptools
  129. copying build/lib/setuptools/archive_util.py -> build/bdist.linux-x86_64/egg/setuptools
  130. copying build/lib/setuptools/dist.py -> build/bdist.linux-x86_64/egg/setuptools
  131. copying build/lib/setuptools/script (dev).tmpl -> build/bdist.linux-x86_64/egg/setuptools
  132. copying build/lib/setuptools/py27compat.py -> build/bdist.linux-x86_64/egg/setuptools
  133. copying build/lib/setuptools/msvc9_support.py -> build/bdist.linux-x86_64/egg/setuptools
  134. copying build/lib/setuptools/version.py -> build/bdist.linux-x86_64/egg/setuptools
  135. copying build/lib/setuptools/compat.py -> build/bdist.linux-x86_64/egg/setuptools
  136. copying build/lib/setuptools/__init__.py -> build/bdist.linux-x86_64/egg/setuptools
  137. copying build/lib/setuptools/utils.py -> build/bdist.linux-x86_64/egg/setuptools
  138. copying build/lib/setuptools/sandbox.py -> build/bdist.linux-x86_64/egg/setuptools
  139. copying build/lib/setuptools/extension.py -> build/bdist.linux-x86_64/egg/setuptools
  140. copying build/lib/setuptools/lib2to3_ex.py -> build/bdist.linux-x86_64/egg/setuptools
  141. copying build/lib/setuptools/depends.py -> build/bdist.linux-x86_64/egg/setuptools
  142. copying build/lib/setuptools/ssl_support.py -> build/bdist.linux-x86_64/egg/setuptools
  143. copying build/lib/setuptools/site-patch.py -> build/bdist.linux-x86_64/egg/setuptools
  144. creating build/bdist.linux-x86_64/egg/_markerlib
  145. copying build/lib/_markerlib/markers.py -> build/bdist.linux-x86_64/egg/_markerlib
  146. copying build/lib/_markerlib/__init__.py -> build/bdist.linux-x86_64/egg/_markerlib
  147. copying build/lib/easy_install.py -> build/bdist.linux-x86_64/egg
  148. creating build/bdist.linux-x86_64/egg/pkg_resources
  149. copying build/lib/pkg_resources/__init__.py -> build/bdist.linux-x86_64/egg/pkg_resources
  150. creating build/bdist.linux-x86_64/egg/pkg_resources/_vendor
  151. copying build/lib/pkg_resources/_vendor/__init__.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor
  152. creating build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging
  153. copying build/lib/pkg_resources/_vendor/packaging/_structures.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging
  154. copying build/lib/pkg_resources/_vendor/packaging/__about__.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging
  155. copying build/lib/pkg_resources/_vendor/packaging/specifiers.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging
  156. copying build/lib/pkg_resources/_vendor/packaging/version.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging
  157. copying build/lib/pkg_resources/_vendor/packaging/__init__.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging
  158. copying build/lib/pkg_resources/_vendor/packaging/_compat.py -> build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging
  159. byte-compiling build/bdist.linux-x86_64/egg/setuptools/py26compat.py to py26compat.pyc
  160. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/bdist_rpm.py to bdist_rpm.pyc
  161. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/develop.py to develop.pyc
  162. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/build_ext.py to build_ext.pyc
  163. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/install.py to install.pyc
  164. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/upload_docs.py to upload_docs.pyc
  165. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/register.py to register.pyc
  166. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/build_py.py to build_py.pyc
  167. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/saveopts.py to saveopts.pyc
  168. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/alias.py to alias.pyc
  169. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/install_egg_info.py to install_egg_info.pyc
  170. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/__init__.py to __init__.pyc
  171. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/test.py to test.pyc
  172. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py to easy_install.pyc
  173. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/rotate.py to rotate.pyc
  174. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/sdist.py to sdist.pyc
  175. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/setopt.py to setopt.pyc
  176. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/egg_info.py to egg_info.pyc
  177. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/bdist_egg.py to bdist_egg.pyc
  178. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/install_scripts.py to install_scripts.pyc
  179. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/install_lib.py to install_lib.pyc
  180. byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/bdist_wininst.py to bdist_wininst.pyc
  181. byte-compiling build/bdist.linux-x86_64/egg/setuptools/unicode_utils.py to unicode_utils.pyc
  182. byte-compiling build/bdist.linux-x86_64/egg/setuptools/py31compat.py to py31compat.pyc
  183. byte-compiling build/bdist.linux-x86_64/egg/setuptools/windows_support.py to windows_support.pyc
  184. byte-compiling build/bdist.linux-x86_64/egg/setuptools/package_index.py to package_index.pyc
  185. byte-compiling build/bdist.linux-x86_64/egg/setuptools/archive_util.py to archive_util.pyc
  186. byte-compiling build/bdist.linux-x86_64/egg/setuptools/dist.py to dist.pyc
  187. byte-compiling build/bdist.linux-x86_64/egg/setuptools/py27compat.py to py27compat.pyc
  188. byte-compiling build/bdist.linux-x86_64/egg/setuptools/msvc9_support.py to msvc9_support.pyc
  189. byte-compiling build/bdist.linux-x86_64/egg/setuptools/version.py to version.pyc
  190. byte-compiling build/bdist.linux-x86_64/egg/setuptools/compat.py to compat.pyc
  191. byte-compiling build/bdist.linux-x86_64/egg/setuptools/__init__.py to __init__.pyc
  192. byte-compiling build/bdist.linux-x86_64/egg/setuptools/utils.py to utils.pyc
  193. byte-compiling build/bdist.linux-x86_64/egg/setuptools/sandbox.py to sandbox.pyc
  194. byte-compiling build/bdist.linux-x86_64/egg/setuptools/extension.py to extension.pyc
  195. byte-compiling build/bdist.linux-x86_64/egg/setuptools/lib2to3_ex.py to lib2to3_ex.pyc
  196. byte-compiling build/bdist.linux-x86_64/egg/setuptools/depends.py to depends.pyc
  197. byte-compiling build/bdist.linux-x86_64/egg/setuptools/ssl_support.py to ssl_support.pyc
  198. byte-compiling build/bdist.linux-x86_64/egg/setuptools/site-patch.py to site-patch.pyc
  199. byte-compiling build/bdist.linux-x86_64/egg/_markerlib/markers.py to markers.pyc
  200. byte-compiling build/bdist.linux-x86_64/egg/_markerlib/__init__.py to __init__.pyc
  201. byte-compiling build/bdist.linux-x86_64/egg/easy_install.py to easy_install.pyc
  202. byte-compiling build/bdist.linux-x86_64/egg/pkg_resources/__init__.py to __init__.pyc
  203. byte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/__init__.py to __init__.pyc
  204. byte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/_structures.py to _structures.pyc
  205. byte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/__about__.py to __about__.pyc
  206. byte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/specifiers.py to specifiers.pyc
  207. byte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/version.py to version.pyc
  208. byte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/__init__.py to __init__.pyc
  209. byte-compiling build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/_compat.py to _compat.pyc
  210. creating build/bdist.linux-x86_64/egg/EGG-INFO
  211. copying setuptools.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
  212. copying setuptools.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
  213. copying setuptools.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
  214. copying setuptools.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
  215. copying setuptools.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
  216. copying setuptools.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
  217. copying setuptools.egg-info/zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
  218. creating dist
  219. creating 'dist/setuptools-18.2-py2.6.egg' and adding 'build/bdist.linux-x86_64/egg' to it
  220. removing 'build/bdist.linux-x86_64/egg' (and everything under it)
  221. Processing setuptools-18.2-py2.6.egg
  222. Copying setuptools-18.2-py2.6.egg to /usr/lib/python2.6/site-packages
  223. Adding setuptools 18.2 to easy-install.pth file
  224. Installing easy_install script to /usr/bin
  225. Installing easy_install-2.6 script to /usr/bin
  226. Installed /usr/lib/python2.6/site-packages/setuptools-18.2-py2.6.egg
  227. Processing dependencies for setuptools==18.2
  228. Finished processing dependencies for setuptools==18.2
  229. #
  230. 使用这种方法安装后,可以看到目录中会自动下载setuptools的软件包,也可以查看easy\_install可用的命令:
  231. # ls -la
  232. total 888
  233. drwxr-xr-x. 3 root root 4096 Aug 27 11:11 .
  234. drwxr-xr-x. 12 root root 4096 Apr 15 01:16 ..
  235. -rw-r--r-- 1 root root 11432 Aug 20 01:00 ez_setup.py
  236. drwxr-xr-x 9 1000 1000 4096 Aug 27 11:18 psutil-2.0.0
  237. -rw-r--r-- 1 root root 207168 May 15 01:30 psutil-2.0.0.tar.gz
  238. -rw-r--r-- 1 root root 674659 Aug 27 10:45 setuptools-18.2.zip
  239. # which easy_install
  240. /usr/bin/easy_install
  241. # easy_install --help
  242. Global options:
  243. --verbose (-v) run verbosely (default)
  244. --quiet (-q) run quietly (turns verbosity off)
  245. --dry-run (-n) don't actually do anything
  246. --help (-h) show detailed help message
  247. Options for 'easy_install' command:
  248. --prefix installation prefix
  249. --zip-ok (-z) install package as a zipfile
  250. --multi-version (-m) make apps have to require() a version
  251. --upgrade (-U) force upgrade (searches PyPI for latest versions)
  252. --install-dir (-d) install package to DIR
  253. --script-dir (-s) install scripts to DIR
  254. --exclude-scripts (-x) Don't install scripts
  255. --always-copy (-a) Copy all needed packages to install dir
  256. --index-url (-i) base URL of Python Package Index
  257. --find-links (-f) additional URL(s) to search for packages
  258. --build-directory (-b) download/extract/build in DIR; keep the results
  259. --optimize (-O) also compile with optimization: -O1 for "python -
  260. O", -O2 for "python -OO", and -O0 to disable
  261. [default: -O0]
  262. --record filename in which to record list of installed
  263. files
  264. --always-unzip (-Z) don't install as a zipfile, no matter what
  265. --site-dirs (-S) list of directories where .pth files work
  266. --editable (-e) Install specified packages in editable form
  267. --no-deps (-N) don't install dependencies
  268. --allow-hosts (-H) pattern(s) that hostnames must match
  269. --local-snapshots-ok (-l) allow building eggs from local checkouts
  270. --version print version information and exit
  271. --no-find-links Don't load find-links defined in packages being
  272. installed
  273. --user install in user site-package
  274. '/root/.local/lib/python2.6/site-packages'
  275. usage: easy_install [options] requirement_or_url ...
  276. or: easy_install --help

二、easy_install 命令的使用方式与安装举例

  1. setuptools安装成功后,easy\_install有多种使用方法:
  2. a、通过模块名称来安装。setuptools会自动搜索PyPI 以查找最新版本的模块。如果找到的话,她会自动下载、编译和安装:例如

easy_install SQLObject

  1. 说明,安装过程可能需要权限,如果是ubuntu的话,可以加上sudo
  2. b、指定查找页面("download page")来使用名称和版本信息来安装或升级一个模块:

easy_install -f http://pythonpaste.org/package_index.html SQLObject

  1. c、从指定模块下载地址来下载模块源码并在下载成功之后编译安装

easy_install http://example.com/path/to/MyPackage-1.2.3.tgz

  1. d、在本地已经存在的egg文件基础上来安装模块

easy_install /my_downloads/OtherPackage-3.2.1-py2.3.egg

  1. e、升级一个已经安装的模块到最新版本,如果在PyPI中这个模块有最新版本。

easy_install —upgrade PyProtocols

  1. f、从源码中安装模块(源码已经下载并解压到当前文件夹下)(New in 0.5a9)

easy_install .

  1. g、模块卸载 easy\_install -m package-name (比如easy\_install -m pylab)
  2. 如果想删除通过easy\_install安装的软件包,比如说:MySQL-python,可以执行命令:

easy_install -m MySQL-python

  1. 注:此操作会从easy-install.pth文件里把MySQL-python的相关信息抹去,剩下的egg文件,你可以手动删除。
  2. 上面这些具体细节可以参考easy install的官方网站:[http://peak.telecommunity.com/DevCenter/EasyInstall][http_peak.telecommunity.com_DevCenter_EasyInstall]
  3. 例如,用第一种方法安装SQLObject模块:
  4. # easy_install -f http://pythonpaste.org/package_index.html SQLObject
  5. Searching for SQLObject
  6. Reading http://pythonpaste.org/package_index.html
  7. Reading https://pypi.python.org/simple/SQLObject/
  8. Best match: SQLObject 3.0.0a1.dev20150327
  9. Downloading https://pypi.python.org/packages/2.6/S/SQLObject/SQLObject-3.0.0a1dev_20150327-py2.6.egg#md5=de05545626c8c4179ebb787fb2b0cf96
  10. Processing SQLObject-3.0.0a1dev_20150327-py2.6.egg
  11. creating /usr/lib/python2.6/site-packages/SQLObject-3.0.0a1dev_20150327-py2.6.egg
  12. Extracting SQLObject-3.0.0a1dev_20150327-py2.6.egg to /usr/lib/python2.6/site-packages
  13. Adding SQLObject 3.0.0a1.dev20150327 to easy-install.pth file
  14. Installing sqlobject-admin script to /usr/bin
  15. Installing sqlobject-convertOldURI script to /usr/bin
  16. Installed /usr/lib/python2.6/site-packages/SQLObject-3.0.0a1dev_20150327-py2.6.egg
  17. Processing dependencies for SQLObject
  18. Searching for PyDispatcher>=2.0.4
  19. Reading https://pypi.python.org/simple/PyDispatcher/
  20. Best match: PyDispatcher 2.0.5
  21. Downloading https://pypi.python.org/packages/source/P/PyDispatcher/PyDispatcher-2.0.5.zip#md5=13bcd5142583a2ca4bae0664c4a235e0
  22. Processing PyDispatcher-2.0.5.zip
  23. Writing /tmp/easy_install-CKT2_x/PyDispatcher-2.0.5/setup.cfg
  24. 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
  25. warning: no previously-included files matching '*.bat' found anywhere in distribution
  26. warning: no previously-included files matching './CVS' found anywhere in distribution
  27. warning: no previously-included files matching '.cvsignore' found anywhere in distribution
  28. zip_safe flag not set; analyzing archive contents...
  29. Moving PyDispatcher-2.0.5-py2.6.egg to /usr/lib/python2.6/site-packages
  30. Adding PyDispatcher 2.0.5 to easy-install.pth file
  31. Installed /usr/lib/python2.6/site-packages/PyDispatcher-2.0.5-py2.6.egg
  32. Searching for FormEncode>=1.1.1
  33. Reading https://pypi.python.org/simple/FormEncode/
  34. Best match: FormEncode 1.3.0
  35. Downloading https://pypi.python.org/packages/source/F/FormEncode/FormEncode-1.3.0.zip#md5=6df12d60bf3179402f2c2efd1129eb74
  36. Processing FormEncode-1.3.0.zip
  37. Writing /tmp/easy_install-wGGheC/FormEncode-1.3.0/setup.cfg
  38. Running FormEncode-1.3.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-wGGheC/FormEncode-1.3.0/egg-dist-tmp-msPx0T
  39. warning: no files found matching '*.py' under directory '.'
  40. warning: no files found matching '*.html' under directory 'docs'
  41. warning: no files found matching '*.py' under directory 'formencode/i18n'
  42. warning: no previously-included files matching '*.pyc' found under directory '.'
  43. warning: no previously-included files matching '*.pyo' found under directory '.'
  44. warning: no previously-included files matching '*~' found under directory '.'
  45. no previously-included directories found matching 'docs/_build'
  46. no previously-included directories found matching '**/.svn'
  47. no previously-included directories found matching '.hg'
  48. no previously-included directories found matching '.git'
  49. creating /usr/lib/python2.6/site-packages/FormEncode-1.3.0-py2.6.egg
  50. Extracting FormEncode-1.3.0-py2.6.egg to /usr/lib/python2.6/site-packages
  51. Adding FormEncode 1.3.0 to easy-install.pth file
  52. Installed /usr/lib/python2.6/site-packages/FormEncode-1.3.0-py2.6.egg
  53. Finished processing dependencies for SQLObject
  54. 这样 SQLObject模块就安装成功了。

三、以源码方式安装psutil模块
Python中的psutil模块能够获取系统运行进程和使用率,对于系统监控还是比较有意义的。
下面用easy_install以源码方式安装psutil模块:

  1. # cd /usr/local/src
  2. # wget https://pypi.python.org/packages/source/p/psutil/psutil-2.0.0.tar.gz --no-check-certificate
  3. # tar -zxvf psutil-2.0.0.tar.gz
  4. # cd psutil-2.0.0
  5. # pwd
  6. /usr/local/src/psutil-2.0.0
  7. [root@centos01 psutil-2.0.0]# ll
  8. total 128
  9. drwxr-xr-x 4 root root 4096 Aug 27 10:57 build
  10. -rw-r--r-- 1 1000 1000 3547 Mar 9 2014 CREDITS
  11. drwxr-xr-x 5 1000 1000 4096 Mar 10 2014 docs
  12. drwxr-xr-x 2 1000 1000 4096 Mar 10 2014 examples
  13. -rw-r--r-- 1 1000 1000 31828 Mar 10 2014 HISTORY
  14. -rw-r--r-- 1 1000 1000 1584 Mar 4 2014 LICENSE
  15. -rw-r--r-- 1 1000 1000 5797 Mar 4 2014 make.bat
  16. -rw-r--r-- 1 1000 1000 1593 Mar 4 2014 Makefile
  17. -rw-r--r-- 1 1000 1000 308 Mar 4 2014 MANIFEST.in
  18. -rw-r--r-- 1 1000 1000 13281 Mar 10 2014 PKG-INFO
  19. drwxr-xr-x 3 1000 1000 4096 Mar 10 2014 psutil
  20. drwxr-xr-x 2 1000 1000 4096 Mar 10 2014 psutil.egg-info
  21. -rw-r--r-- 1 1000 1000 8740 Mar 10 2014 README
  22. -rw-r--r-- 1 1000 1000 59 Mar 10 2014 setup.cfg
  23. -rw-r--r-- 1 1000 1000 6488 Mar 4 2014 setup.py
  24. drwxr-xr-x 2 1000 1000 4096 Mar 10 2014 test
  25. -rw-r--r-- 1 1000 1000 4970 Mar 10 2014 TODO
  26. [root@centos01 psutil-2.0.0]#
  27. [root@centos01 psutil-2.0.0]# easy_install .
  28. Processing .
  29. Writing /usr/local/src/psutil-2.0.0/setup.cfg
  30. Running setup.py -q bdist_egg --dist-dir /usr/local/src/psutil-2.0.0/egg-dist-tmp-CVh5Pq
  31. warning: no previously-included files matching '*' found under directory 'docs/_build'
  32. psutil/_psutil_linux.c:12:20: error: Python.h: No such file or directory
  33. In file included from psutil/_psutil_linux.c:23:
  34. psutil/_psutil_linux.h:11: error: expected ‘=’, ‘,’, ‘;’, asm or __attribute__ before ‘*’ token
  35. psutil/_psutil_linux.h:12: error: expected ‘=’, ‘,’, ‘;’, asm or __attribute__ before ‘*’ token
  36. psutil/_psutil_linux.h:13: error: expected ‘=’, ‘,’, ‘;’, asm or __attribute__ before ‘*’ token
  37. psutil/_psutil_linux.h:14: error: expected ‘=’, ‘,’, ‘;’, asm or __attribute__ before ‘*’ token
  38. psutil/_psutil_linux.h:18: error: expected ‘=’, ‘,’, ‘;’, asm or __attribute__ before ‘*’ token
  39. psutil/_psutil_linux.h:19: error: expected ‘=’, ‘,’, ‘;’, asm or __attribute__ before ‘*’ token
  40. psutil/_psutil_linux.h:20: error: expected ‘=’, ‘,’, ‘;’, asm or __attribute__ before ‘*’ token
  41. psutil/_psutil_linux.c: In function ioprio_get’:
  42. psutil/_psutil_linux.c:50: warning: implicit declaration of function syscall
  43. psutil/_psutil_linux.c: At top level:
  44. psutil/_psutil_linux.c:70: error: expected ‘=’, ‘,’, ‘;’, asm or __attribute__ before ‘*’ token
  45. psutil/_psutil_linux.c:93: error: expected ‘=’, ‘,’, ‘;’, asm or __attribute__ before ‘*’ token
  46. psutil/_psutil_linux.c:181: error: expected ‘=’, ‘,’, ‘;’, asm or __attribute__ before ‘*’ token
  47. psutil/_psutil_linux.c:232: error: expected ‘=’, ‘,’, ‘;’, asm or __attribute__ before ‘*’ token
  48. psutil/_psutil_linux.c:255: error: expected ‘=’, ‘,’, ‘;’, asm or __attribute__ before ‘*’ token
  49. psutil/_psutil_linux.c:275: error: expected ‘=’, ‘,’, ‘;’, asm or __attribute__ before ‘*’ token
  50. psutil/_psutil_linux.c:336: error: expected ‘=’, ‘,’, ‘;’, asm or __attribute__ before ‘*’ token
  51. psutil/_psutil_linux.c:384: error: expected ‘=’, ‘,’, ‘;’, asm or __attribute__ before PsutilMethods
  52. psutil/_psutil_linux.c:421: error: expected specifier-qualifier-list before PyObject
  53. psutil/_psutil_linux.c: In function init_psutil_linux’:
  54. psutil/_psutil_linux.c:470: error: PyObject undeclared (first use in this function)
  55. psutil/_psutil_linux.c:470: error: (Each undeclared identifier is reported only once
  56. psutil/_psutil_linux.c:470: error: for each function it appears in.)
  57. psutil/_psutil_linux.c:470: error: module undeclared (first use in this function)
  58. psutil/_psutil_linux.c:470: warning: implicit declaration of function Py_InitModule
  59. psutil/_psutil_linux.c:470: error: PsutilMethods undeclared (first use in this function)
  60. error: Setup script exited with error: command 'gcc' failed with exit status 1
  61. 使用easy\_install进行源码安装时,可能会有如下报错:
  62. 用安装python模块出现error: command 'gcc' failed with exit status 1 ,明明装了gcc的,怎么会不行呢,然后发觉是failed不是not found,这说明这个错误个gcc没多

大关系,应该是缺少某些功能模块,然后谷歌了一下,先后安装了python-devel,libffi-devel后还是不行,最后发觉要安装openssl-devel才行

  1. 可如下命令行安装:

yum install gcc libffi-devel python-devel openssl-devel

  1. 过程如下:
  2. # yum install gcc libffi-devel python-devel openssl-devel
  3. Loaded plugins: fastestmirror, refresh-packagekit, security
  4. Loading mirror speeds from cached hostfile
  5. * base: mirror.bit.edu.cn
  6. * extras: mirrors.btte.net
  7. * updates: mirrors.btte.net
  8. Setting up Install Process
  9. Package gcc-4.4.7-16.el6.x86_64 already installed and latest version
  10. Package libffi-devel-3.0.5-3.2.el6.x86_64 already installed and latest version
  11. Package openssl-devel-1.0.1e-42.el6.x86_64 already installed and latest version
  12. Resolving Dependencies
  13. --> Running transaction check
  14. ---> Package python-devel.x86_64 0:2.6.6-64.el6 will be installed
  15. --> Processing Dependency: python-libs(x86-64) = 2.6.6-64.el6 for package: python-devel-2.6.6-64.el6.x86_64
  16. --> Processing Dependency: python = 2.6.6-64.el6 for package: python-devel-2.6.6-64.el6.x86_64
  17. --> Running transaction check
  18. ---> Package python.x86_64 0:2.6.6-51.el6 will be updated
  19. ---> Package python.x86_64 0:2.6.6-64.el6 will be an update
  20. ---> Package python-libs.x86_64 0:2.6.6-51.el6 will be updated
  21. ---> Package python-libs.x86_64 0:2.6.6-64.el6 will be an update
  22. --> Finished Dependency Resolution
  23. Dependencies Resolved
  24. =============================================================================================================
  25. Package Arch Version Repository Size
  26. =============================================================================================================
  27. Installing:
  28. python-devel x86_64 2.6.6-64.el6 base 172 k
  29. Updating for dependencies:
  30. python x86_64 2.6.6-64.el6 base 76 k
  31. python-libs x86_64 2.6.6-64.el6 base 5.3 M
  32. Transaction Summary
  33. =============================================================================================================
  34. Install 1 Package(s)
  35. Upgrade 2 Package(s)
  36. Total download size: 5.6 M
  37. Is this ok [y/N]: y
  38. Downloading Packages:
  39. (1/3): python-2.6.6-64.el6.x86_64.rpm | 76 kB 00:00
  40. (2/3): python-devel-2.6.6-64.el6.x86_64.rpm | 172 kB 00:00
  41. (3/3): python-libs-2.6.6-64.el6.x86_64.rpm | 5.3 MB 00:17
  42. -------------------------------------------------------------------------------------------------------------
  43. Total 317 kB/s | 5.6 MB 00:17
  44. Running rpm_check_debug
  45. Running Transaction Test
  46. Transaction Test Succeeded
  47. Running Transaction
  48. Updating : python-2.6.6-64.el6.x86_64 1/5
  49. Updating : python-libs-2.6.6-64.el6.x86_64 2/5
  50. Installing : python-devel-2.6.6-64.el6.x86_64 3/5
  51. Cleanup : python-2.6.6-51.el6.x86_64 4/5
  52. Cleanup : python-libs-2.6.6-51.el6.x86_64 5/5
  53. Verifying : python-devel-2.6.6-64.el6.x86_64 1/5
  54. Verifying : python-libs-2.6.6-64.el6.x86_64 2/5
  55. Verifying : python-2.6.6-64.el6.x86_64 3/5
  56. Verifying : python-libs-2.6.6-51.el6.x86_64 4/5
  57. Verifying : python-2.6.6-51.el6.x86_64 5/5
  58. Installed:
  59. python-devel.x86_64 0:2.6.6-64.el6
  60. Dependency Updated:
  61. python.x86_64 0:2.6.6-64.el6 python-libs.x86_64 0:2.6.6-64.el6
  62. Complete!
  63. 再次执行easy\_install 安装命令:
  64. # easy_install .
  65. Processing .
  66. Writing /usr/local/src/psutil-2.0.0/setup.cfg
  67. Running setup.py -q bdist_egg --dist-dir /usr/local/src/psutil-2.0.0/egg-dist-tmp-wshhD1
  68. warning: no previously-included files matching '*' found under directory 'docs/_build'
  69. psutil/_psutil_linux.c: In function psutil_proc_cpu_affinity_set’:
  70. psutil/_psutil_linux.c:327: warning: suggest explicit braces to avoid ambiguous else
  71. zip_safe flag not set; analyzing archive contents...
  72. Moving psutil-2.0.0-py2.6-linux-x86_64.egg to /usr/lib/python2.6/site-packages
  73. Adding psutil 2.0.0 to easy-install.pth file
  74. Installed /usr/lib/python2.6/site-packages/psutil-2.0.0-py2.6-linux-x86_64.egg
  75. Processing dependencies for psutil==2.0.0
  76. Finished processing dependencies for psutil==2.0.0
  77. psutil模块安装完毕后,可以在Python终端中调用各种命令来获取系统状态:
  78. # python
  79. Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
  80. [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
  81. Type "help", "copyright", "credits" or "license" for more information.
  82. >>> import psutil
  83. /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
  84. /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
  85. >>> psutil.cpu_times()
  86. scputimes(user=43.100000000000001, nice=0.0, system=36.119999999999997, idle=10653.4, iowait=285.0, irq=1.0600000000000001, softirq=3.1000000000000001,
  87. steal=0.0, guest=0.0)
  88. >>> psutil.cpu_times().user
  89. 43.130000000000003
  90. >>> psutil.cpu_count()
  91. 4
  92. >>> psutil.cpu_count(logical=False)
  93. 2
  94. >>> mem = psutil.virtual_memory()
  95. >>> mem
  96. svmem(total=1036648448L, available=733806592L, percent=29.199999999999999, used=888340480L, free=148307968L, active=244699136, inactive=500060160,
  97. buffers=47853568L, cached=537645056)
  98. >>> mem.total
  99. 1036648448L
  100. >>> mem.free
  101. 148307968L
  102. >>> psutil.swap_memory()
  103. sswap(total=2080366592L, used=8192L, free=2080358400L, percent=0.0, sin=0, sout=0)
  104. >>>
  105. >>> psutil.disk_partition()
  106. Traceback (most recent call last):
  107. File "<stdin>", line 1, in <module>
  108. AttributeError: 'ModuleWrapper' object has no attribute 'disk_partition'
  109. >>> psutil.disk_partitions()
  110. [sdiskpart(device='/dev/mapper/vg_centos01-lv_root', mountpoint='/', fstype='ext4', opts='rw'), sdiskpart(device='/dev/sda1', mountpoint='/boot',
  111. fstype='ext4', opts='rw')]
  112. >>>
  113. >>> psutil.disk_usage('/')
  114. sdiskusage(total=18569568256, used=4755951616, free=12870320128, percent=25.600000000000001)
  115. >>> psutil.disk_io_counters()
  116. sdiskio(read_count=37622, write_count=230886, read_bytes=688139264, write_bytes=1625135104, read_time=664928, write_time=22065267)
  117. >>>
  118. >>> psutil.disk_io_counters(perdisk=True)
  119. {'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,
  120. write_count=32509, read_bytes=343094272, write_bytes=812621824, read_time=282044, write_time=1616651), 'dm-0': sdiskio(read_count=21964,
  121. write_count=198394, read_bytes=341320704, write_bytes=812621824, read_time=382104, write_time=20448581), 'sda1': sdiskio(read_count=597, write_count=7,
  122. read_bytes=2405376, write_bytes=14336, read_time=127, write_time=93)}
  123. >>>
  124. >>> psutil.net_io_counters()
  125. snetio(bytes_sent=3186898, bytes_recv=119382022, packets_sent=43509, packets_recv=84308, errin=0, errout=0, dropin=0, dropout=0)
  126. >>>
  127. >>> psutil.net_io_counters(pernic=True)
  128. {'lo': snetio(bytes_sent=960, bytes_recv=960, packets_sent=16, packets_recv=16, errin=0, errout=0, dropin=0, dropout=0), 'eth0': snetio
  129. (bytes_sent=3192258, bytes_recv=119388892, packets_sent=43535, packets_recv=84361, errin=0, errout=0, dropin=0, dropout=0)}
  130. >>>
  131. >>> psutil.users()
  132. [suser(name='root', terminal='tty1', host=':0', started=1440643328.0), suser(name='root', terminal='pts/0', host='localhost', started=1440643328.0),
  133. suser(name='root', terminal='pts/1', host='192.168.226.1', started=1440643328.0)]
  134. >>> import psutil,datetime
  135. >>>
  136. >>> psutil.boot_time()
  137. 1440642945.0
  138. >>>
  139. >>> datetime.datetime.fromtimestamp(psutil.boot_time()).strftime("%Y-%m-%d %H:%M:%S")
  140. '2015-08-27 10:35:45'
  141. >>>

发表评论

表情:
评论列表 (有 0 条评论,309人围观)

还没有评论,来说两句吧...

相关阅读