码迷,mamicode.com
首页 > 编程语言 > 详细

解决python引包错误

时间:2020-05-26 20:51:11      阅读:88      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!