如何将写好的脚本或者是模块加入Python的搜索路径?
>>>import sys
>>> sys.path
['', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages']
#出来的是一个路径列表,python会从这里搜索路径,其中模块应该存放在/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
>>>sys.path.append("/desktop/python3.4/test.py")
#把test.py的路径加入python搜索路径里去
>>>sys.path
['', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages','/desktop/python3.4/test.py']
>>>import test
"Hellow world"
下面关于Python的文章您也可能喜欢,不妨看看:
Linux下Python的安装以及注意事项
Ubuntu 14.04 下安装使用Python rq模块
CentOS上源码安装Python3.4
《Python核心编程 第二版》.(Wesley J. Chun ).[高清PDF中文版]
《Python开发技术详解》.( 周伟,宗杰).[高清PDF扫描版+随书视频+代码]
Python脚本获取Linux系统信息