import os
try:
import jieba # 导入模块
except ModuleNotFoundError:
print('正在安装jieba,请稍等...')
os.system('pip install jieba') # 安装jieba模块
print(range(0,5))
import sys
# 检测Python版本号
__MAJOR, __MINOR, __MICRO = sys.version_info[0], sys.version_info[1], sys.version_info[2]
if __MAJOR < 3: # 判断主版本号是否小于3
print('Python版本号过低,当前版本为 %d.%d.%d, 请重装Python解释器' % (__MAJOR, __MINOR, __MICRO))
exit() # 退出程序
return load(os.path.join(directory, filename))
return load_default()
def load_path(filename):
"""
Load font file. Same as :py:func:`~PIL.ImageFont.load`, but searches for a
bitmap font along the Python path.
:param filename: Name of font file.
:return: A font object.
:exception IOError: If the file could not be read.
"""
for directory in sys.path:
if isDirectory(directory):
if not isinstance(filename, str):
if py3:
filename = filename.decode("utf-8")
else:
filename = filename.encode("utf-8")
try:
return load_default() # 修改后的代码
except IOError:
pass
raise IOError("cannot find font file")