Python模块调用时的路径查找

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python模块调用时的路径查找相关的知识,希望对你有一定的参考价值。

 

import sys 
import os 

base_dir = os.path.dirname(os.path.abspath(__file__))

sys.path.append(base_dir) 
os.path.abspath(__file__)  确认*.py的绝对路径
os.path.dirname(os.path.abspath(__file__)) 返回*.py的上一级文件路径

sys.path.append(base_dir) 添加搜索路径


 





以上是关于Python模块调用时的路径查找的主要内容,如果未能解决你的问题,请参考以下文章