1 查看python中的查找模块的路径
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import
sys
sys.path
['',
'/usr/bin'
,
'/usr/lib64/python26.zip'
,
'/usr/lib64/python2.6'
,
'/usr/lib64/python2.6/plat-linux2'
,
'/usr/lib64/python2.6/lib-tk'
,
'/usr/lib64/python2.6/lib-old'
,
'/usr/lib64/python2.6/lib-dynload'
,
'/usr/lib64/python2.6/site-packages'
,
'/usr/lib64/python2.6/site-packages/gtk-2.0'
,
'/usr/lib/python2.6/site-packages'
,
'/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info'
,
'/usr/lib/python2.6/site-packages/IPython/extensions'
]
|
2 查看一个模块的具体路径
方法1: 利用__file__属性
1
2
3
|
import
MySQLdb
MySQLdb.__file__
'/usr/lib64/python2.6/site-packages/MySQLdb/__init__.pyc'
|
方法二:利用sys模块的modules方法
1
2
3
|
import
sys
sys.modules[
'MySQLdb'
]
<module
'MySQLdb'
from
'/usr/lib64/python2.6/site-packages/MySQLdb/__init__.pyc'
>
|
cuizhiliang