引入Python包时路径问题

引入Python包时路径问题

当你把所有程序整合成一个python包,从外部调用时会找不到其他模块的位置。

此时,需要再__init__.py(本来是空白的)中加入以下代码:

import sys
import os
current_path = os.path.dirname(os.path.abspath(__file__))
sys.path.append(current_path)

这样便把引入模块时的绝对路径确定了。

猜你喜欢

转载自blog.csdn.net/weixin_48419914/article/details/115025339