Question
路径问题
-
python导入自己的包,嵌套后文件夹相对路径产生错误的解决方法:
import os import sys current_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.join(current_dir, ".")) import 你想导入的包 -
文件由于层层嵌套,文件夹相对路径产生错误的解决方法:
import os import sys current_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.join(current_dir, ".")) file_path = current_dir + '相对路径'