# coding=utf8# date = 2019/12/23 19:54# 清白丶之年__照林""" # Solve Import Lib Error Add Some Path To Python Path"""import osimport sysclass PythonPath: def add_lib_to_path(self, lib_path): with os.popen(r‘where python‘, ‘r‘) as file: python_path = str(file.read()).split(r"\python.exe")[0] print(python_path) python_path2 = os.path.join(python_path, "Lib", "site-packages", "JustTest.pth") # python_path2 = python_path+os.sep+ "Lib"+ os.sep+ "site-packages"+ os.sep+"JustTest.pth" print(python_path2) file.close() with open("%s" % python_path2, "w", encoding="utf8") as file2: file2.write(lib_path) file2.close() def add_lib_to_path2(self, Path): for i in Path: sys.path.append(i)if __name__ == ‘__main__‘: pt = PythonPath() # 下面方法入参为包绝对路径 pt.add_lib_to_path("D:\zk")