出现环境:CentOS 7服务器,Anaconda,python=3.8
出现问题:jieba报错:
PermissionError: [Errno 1] Operation not permitted: '/tmp/tmpapqf4_5o' -> '/tmp/jieba.cache'
出现原因:jieba想要在系统根目录创建缓存文件/tmp/jieba.cache来存储模型,然而本用户没有权限。因此需要修改jieba源代码
解决方式:
class Tokenizer(object): def __init__(self, dictionary=DEFAULT_DICT): self.lock = threading.RLock() if dictionary == DEFAULT_DICT: self.dictionary = dictionary else: self.dictionary = _get_abs_path(dictionary) self.FREQ = {} self.total = 0 self.user_word_tag_tab = {} self.initialized = False # self.tmp_dir = None//原代码self.tmp_dir = "/home/用户名/anaconda3/envs/虚拟环境名/lib/python3.8/site-packages/jieba/cache" self.cache_file = None
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!