解决python引包错误

Posted zhangzhaolin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决python引包错误相关的知识,希望对你有一定的参考价值。

# 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引包错误的主要内容,如果未能解决你的问题,请参考以下文章

Python的引包小坑

python中路径问题,防止在引包时出现路径错误的问题

python中路径问题,防止在引包时出现路径错误的问题

有哪些python引包的方法?

python入门20 导入模块(引包)

python-DB模块