>>> import sys >>> sys.path ['', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/liangshaohua/Library/Python/3.7/lib/python/site-packages', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages']
python解释器会从当前目录开始,从左到右按顺序查找。前面的我们基本不用,我们经常用的也就是自己写的和site-packages,第三方和内置的都在site-packages里面。
增加模块路径
>>> sys.path.append('module_practice') >>> import my_module ['', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/liangshaohua/Library/Python/3.7/lib/python/site-packages', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages', 'module_practice']
删除模块路径
>>> del sys.path[-1] >>> sys.path ['', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/liangshaohua/Library/Python/3.7/lib/python/site-packages', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages']
注意:增加也只是在当前程序整个程序的运行过程中加了,退出就没有了。
基本翻译
n. 地点;位置;场所
vt. 设置;为…选址