# coding=utf8
# date = 2019/12/23 19:54
# 清白丶之年__照林
""" # Solve Import Lib Error
Add Some Path To Python Path
"""

import os
import sys


class 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")

版权声明:本文为zhangzhaolin原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/zhangzhaolin/p/12967766.html