当我们需要查看PYTHON安装位置或者第三方包的位置时候,记不清楚原来安装到哪里可以使用以下命令来查看
进入PYTHON后
import sys
sys.path则会打印出你的当前版本安装包的位置
例如:
import sys
module = sys.path
for i in module:
….print(i)
D:\SofTwareInstall\py3\python36.zip
D:\SofTwareInstall\py3\DLLs
D:\SofTwareInstall\py3\lib
D:\SofTwareInstall\py3
D:\SofTwareInstall\py3\lib\site-packages`
3.即能打印相关包路径位置
help(‘modules’)
怎么样把自己写的模块加入到python默认就有的搜索路径中呢?不要每次非得import sys; sys.path.append(‘/home/fightlikekobe/python’)才可。
上网找了很多久未果,都来我自己糊里糊涂找到了解决方法,那就是在dist-packages(即/usr/local/lib/python2.7/dist-packages)添加一个路径文件,如mypkpath.pth,必须以.pth为后缀,写上你要加入的文件名称就是了,如我的:
/home/fightlikekobe/python
保存退出,OK!结果自己验证,重启terminal,再次打开python,
>>> import sys
>>> sys.path
[‘/home/fightlikekobe’, ‘/usr/bin’, ‘/usr/local/lib/python2.7/dist-packages/pymysql_sa-1.0-py2.7.egg’, ‘/usr/local/lib/python2.7/dist-packages/PyMySQL-0.5-py2.7.egg’, ‘/usr/local/lib/python2.7/dist-packages/hiredis-0.1.0-py2.7-linux-i686.egg’, ‘/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.7.3-py2.7-linux-i686.egg’, ‘/usr/lib/python2.7’, ‘/usr/lib/python2.7/plat-linux2’, ‘/usr/lib/python2.7/lib-tk’, ‘/usr/lib/python2.7/lib-old’, ‘/usr/lib/python2.7/lib-dynload’, ‘/usr/local/lib/python2.7/dist-packages’, ‘/usr/local/lib/python2.7/dist-packages’, ‘/home/fightlikekobe/python’, ‘/usr/lib/python2.7/dist-packages’, ‘/usr/lib/python2.7/dist-packages/PIL’, ‘/usr/lib/python2.7/dist-packages/gst-0.10’, ‘/usr/lib/python2.7/dist-packages/gtk-2.0’, ‘/usr/lib/pymodules/python2.7’, ‘/usr/lib/python2.7/dist-packages/ubuntu-sso-client’, ‘/usr/lib/python2.7/dist-packages/ubuntuone-client’, ‘/usr/lib/python2.7/dist-packages/ubuntuone-control-panel’, ‘/usr/lib/python2.7/dist-packages/ubuntuone-couch’, ‘/usr/lib/python2.7/dist-packages/ubuntuone-installer’, ‘/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol’, ‘/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode’]