解决python引包错误

2021-01-07 19:33

阅读:770

标签:pen   open   odi   ==   path   utf8   erro   test   %s   

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

解决python引包错误

标签:pen   open   odi   ==   path   utf8   erro   test   %s   

原文地址:https://www.cnblogs.com/zhangzhaolin/p/12967766.html


评论


亲,登录后才可以留言!