安装Python module,我们可以用setuptools工具里面的easy_install命令去安装。
安装setuptools可以参考官网:https://pypi.python.org/pypi/setuptools
#easy_install python_module=version #也可以不用版本号,默认会 装最新的版本
#mkdir -p XXX/lib/python2.7(version)/site-packages #这里用python 2.7 安装module为例
#export PYTHONPATH=XXX/lib/python2.7(version)/site-packages
#easy_install ---prefix=XXX python_module==version
也可以不用easy_install来安装python module,直接用python来安装,需要先下载python module的源代码。
#mkdir -p XXX/lib/python3.2(version)/site-packages #这里用python 3.2 安装module为例
#export PYTHONPATH=XXX/lib/python3.2(version)/site-packages
#wget https://pypi.python.org/packages/source/c/coverage/coverage-3.7.1.tar.gz #这里用coverage为例,先下载源代码
#cd coverage-3.7.1
#python3 setup.py install --prefix=XXX
查看python module版本方法:这里的方法要用到python的pkg_resources这个module,如果没有,首先要先装上。
$ python
Python 2.7.2 (default, Jul 19 2012, 09:31:06)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> pkg_resources.get_distribution('lxml').version #lxml是要查看的python module
'2.3.4'
>>>
查看某个module是否已经安装:
$ python
Python 2.7.2 (default, Jul 19 2012, 09:31:06)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources #查看pkg_resources module是否在当前的python下可以
>>> pkg_resources
>>>
查看python的帮助文档:
>>> help() //进入帮助模式
Welcome to Python 2.6! This is the online help utility.
If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/tutorial/.
Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".
To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics". Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".
help> keywords //查询可用的keywords
Here is a list of the Python keywords. Enter any keyword to get more help.
and elif if print
as else import raise
assert except in return
break exec is try
class finally lambda while
continue for not with
def from or yield
del global pass
help> modules //查询可用的modules
Please wait a moment while I gather a list of all available modules...
BaseHTTPServer bz2 idlelib re
Bastion cPickle ihooks readline
BuiltIn cProfile imageop report
CDROM cStringIO imaplib repr
CGIHTTPServer cairo imghdr resource
CORBA calendar imp rexec
Collections cas imputil rfc822
ConfigParser cgi iniparse rhn
Cookie cgitb inspect rhsm
Crypto chunk invest rlcompleter
DLFCN cmath io robot
DateTime cmd iotop robotparser
DeprecatedBuiltIn code ipachangeconf rpm
DeprecatedOperatingSystem codecs ipaclient rpmUtils
Dialogs codeop ipalib runpy
DocXMLRPCServer collections ipapython scanext
Easter colorsys itertools scdate
HTMLParser commands iwlib sched
IN compileall ixf86config scservices
M2Crypto compiler json select
MimeWriter contextlib kerberos selinux
ORBit cookielib keyword sets
OpenSSL copy ldap setuptools
OperatingSystem copy_reg ldapurl sgmllib
PortableServer cracklib ldif sha
Process createrepo lib2to3 shelve
Queue crypt libiscsi shlex
Remote csv libproxy shutil
Reserved ctypes libsvn signal
SSSDConfig cups libuser simplejson
Screenshot cupsext libvirt site
SimpleHTTPServer cupshelpers libvirtmod slip
SimpleXMLRPCServer curl libxml2 smbc
SocketServer curses libxml2mod smtpd
String datetime linecache smtplib
StringIO dateutil linuxaudiodev snack
TYPES dbhash locale sndhdr
Telnet dbm logging socket
UserDict dbus lxml sos
UserList dbus_bindings macpath spwd
UserString decimal macurl2path sqlite3
XML decorator magic sqlitecachec
_LWPCookieJar default_encoding_utf8 mailbox sre
_MozillaCookieJar deltarpm mailcap sre_compile
__builtin__ dialogs_ipy mako sre_constants
__future__ dialogs_jy markupbase sre_parse
_abcoll dialogs_py markupsafe ssl
_anthy difflib marshal sssd_upgrade_config
_ast dircache math stat
_bisect dis matplotlib statvfs
_bsddb distutils md5 string
_bytesio dl meh stringold
_codecs dmidecode mercurial stringprep
_codecs_cn dmidecodemod mhlib strop
_codecs_hk doctest mimetools struct
_codecs_iso2022 drv_libxml2 mimetypes subprocess
_codecs_jp dsextras mimify sunau
_codecs_kr dsml mmap sunaudio
_codecs_tw dumbdbm modulefinder svn
_collections dummy_thread mpl_toolkits symbol
_cracklib dummy_threading multifile symtable
_crypt easy_install multiprocessing sys
_csv egg mutex syslog
_ctypes email netaddr system_config_keyboard
_curses enchant netrc tabnanny
_curses_panel encodings new tarfile
_dbus_bindings errno nis telnetlib
_dbus_glib_bindings ethtool nntplib tempfile
_deltarpm exceptions nose termios
_elementtree fcntl nss test
_fileio filecmp ntpath textwrap
_functools fileinput nturl2path this
_gamin firstboot numbers thread
_hashlib fnmatch numpy threading
_heapq formatter opcode time
_hotshot fpformat operator timeit
_json fractions optparse timing
_ldap ftplib orca toaiff
_locale functools os token
_lsprof future_builtins os2emxpath tokenize
_multibytecodec gamin ossaudiodev trace
_multiprocessing gc packagekit traceback
_random gconf pango tty
_snack gdbm pangocairo types
_socket genericpath paramiko unicodedata
_sqlite3 getopt parser unittest
_sqlitecache getpass pcardext urlgrabber
_sre gettext pdb urllib
_ssl gio pickle urllib2
_strptime glib pickletools urlparse
_struct glob pipes user
_symtable gmenu pkg_resources uu
_threading_local gnome pkgutil uuid
_warnings gnomeapplet platform virtconv
_weakref gnomecanvas plistlib virtinst
_xmlplus gnomekeyring popen2 vte
abc gnomevfs poplib warnings
abrt_exception_handler gobject posix wave
acutil google posixfile weakref
aifc gpgme posixpath webbrowser
anthy grp pprint webkit
anydbm gst profile whichdb
argparse gstoption pstats wireshark_be
array gtk pty wireshark_gen
asciidocapi gtksourceview2 pwd wnck
ast gtkunixprint py_compile wsgiref
asynchat gtkvnc pyatspi xdg
asyncore gudev pyclbr xdrlib
atexit gv pycurl xf86config
atk gzip pydoc xml
audiodev hashlib pydoc_topics xml2po
audioop heapq pyexpat xmllib
base64 hgext pygst xmlrpclib
bdb hmac pygtk xxsubtype
beaker hotshot pylab yum
binascii hpmudext pynotify yumutils
binhex htmlentitydefs pysss zipfile
bisect htmllib pytz zipimport
bonobo httplib quopri zlib
bsddb ibus random
Enter any module name to get more help. Or, type "modules spam" to search
for modules whose descriptions contain the word "spam".
python 2.7 文档手册 Python Standard Library