yum 位於linux /usr/bin/yumpython
yum命令是python腳本進行編寫的(python 2.6)linux
#!/usr/bin/python2.6 import sys try: import yum except ImportError: print >> sys.stderr, """\ There was a problem importing one of the Python modules required to run yum. The error leading to this problem was: %s Please install a package which provides this module, or verify that the module is installed correctly. It's possible that the above module doesn't match the current version of Python, which is: %s If you cannot solve this problem yourself, please go to the yum faq at: http://yum.baseurl.org/wiki/Faq """ % (sys.exc_value, sys.version) sys.exit(1) sys.path.insert(0, '/usr/share/yum-cli') try: import yummain yummain.user_main(sys.argv[1:], exit_code=True) except KeyboardInterrupt, e: print >> sys.stderr, "\n\nExiting on user cancel." sys.exit(1)
yum腳本會先import一些基礎的包sql
sys,sys是python的基礎庫,非第三方,自帶庫,支持基本系統相關ide
yum,爲實際調用庫,yum腳本會先try的時候import,若是導入不成功會讓你下載moudleui
咱們能夠打印看一下這個yum庫都有那些東西:this
[root@sevck_linux ~]# /usr/bin/python2.6 Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import yum >>> print dir(yum) ['ArchStorage', 'BOOLEAN_STATES', 'ConfigParser', 'ConfigPreProcessor', 'DBVERSION', 'Errors', 'LETTERFLAGS', 'ListPackageSack', 'PATTERNS_INDEXED_MAX', 'PATTERNS_MAX', 'PLUG_OPT_BOOL', 'PLUG_OPT_FLOAT', 'PLUG_OPT_INT', 'PLUG_OPT_STRING', 'PLUG_OPT_WHERE_ALL', 'PLUG_OPT_WHERE_MAIN', 'PLUG_OPT_WHERE_REPO', 'PO_CONFIG', 'PO_DIR', 'PO_DOC', 'PO_FILE', 'PO_GHOST', 'PO_INSTALLEDPKG', 'PO_LOCALPKG', 'PO_REMOTEPKG', 'P_', 'ParsingError', 'REPO_PROBLEM_COMPS', 'REPO_PROBLEM_METADATA', 'REPO_PROBLEM_OTHER', 'REPO_PROBLEM_PACKAGE', 'REPO_PROBLEM_REPOMD', 'RPMTransaction', 'RPM_CHECKSUM_TYPES', 'RPM_TO_SQLITE', 'RepoStorage', 'SYMBOLFLAGS', 'SimpleCliCallBack', 'StringIO', 'TR_DEPENDS', 'TR_DEPENDSON', 'TR_OBSOLETEDBY', 'TR_OBSOLETES', 'TR_UPDATEDBY', 'TR_UPDATES', 'TS_AVAILABLE', 'TS_ERASE', 'TS_FAILED', 'TS_INSTALL', 'TS_INSTALL_STATES', 'TS_OBSOLETED', 'TS_OBSOLETING', 'TS_REMOVE_STATES', 'TS_TRUEINSTALL', 'TS_UPDATE', 'TS_UPDATED', 'TX_BLACK', 'TX_GREY', 'TX_WHITE', 'URLGrabError', 'URLGrabber', 'YUM_PID_FILE', 'YumAvailablePackage', 'YumBase', 'YumInstalledPackage', 'YumLocalPackage', 'YumUrlPackage', '_', '_YumCostExclude', '_YumPreBaseConf', '_YumPreRepoConf', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', '__version_info__', '_rpm_ver_atleast', 'archDifference', 'callbacks', 'canCoinstall', 'compareEVR', 'comparePoEVR', 'comps', 'config', 'constants', 'default_grabber', 'depsolve', 'errno', 'exception2msg', 'fnmatch', 'format_number', 'glob', 'history', 'i18n', 'isMultiLibArch', 'logging', 'logginglevels', 'metalink', 'misc', 'num', 'operator', 'os', 'packageSack', 'packages', 'packagesNewestByName', 'packagesNewestByNameArch', 'parsePackages', 'parser', 'pgpmsg', 'pkgtag_db', 'plugins', 're', 'repoMDObject', 'repos', 'rpm', 'rpmUtils', 'rpmsack', 'rpmtrans', 'sqlitesack', 'sqlutils', 'string', 'tempfile', 'time', 'to_str', 'to_unicode', 'transactioninfo', 'types', 'urlgrabber', 'varReplace', 'warnings', 'weakref', 'yum', 'yumRepo'] >>> exit()
而後就是執行,url
(sys.exc_value, sys.version)
而後就是導入yummainspa
我用2.6嘗試手工import,可是結果失敗,不知道其餘人有沒有和我同樣。一樣但願解答code
[root@sevck_linux ~]# /usr/bin/python2.6 Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import yummain Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named yummain >>>