python中的库及module的 路径
生活随笔
收集整理的這篇文章主要介紹了
python中的库及module的 路径
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
python中的庫及module的 路徑
在python執(zhí)行時,python調(diào)用的庫或者模塊文件,應(yīng)該從哪里來加載呢?
包括了python系統(tǒng)的庫目錄、設(shè)置的環(huán)境變量PYTHONPATH;還可以在python代碼中設(shè)置sys.path,在其中添加自己的模塊路徑。
查看一下python中的sys.path
>>> import sys >>> sys.path ['', '/Users/david/Desktop/python_c', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC'] >>> quit()如果自己有了新的module和package,可以放置到一個自己的固定目錄下,然后設(shè)置PYTHONPATH環(huán)境變量,這樣比較好。也可以在代碼中如下設(shè)置:
import sys sys.path.insert(0, "./path/to/your/modules/") 創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的python中的库及module的 路径的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 晶圆代工产能利用率普遍下滑,或掀起业界价
- 下一篇: opencv_python关于Qt的错误