当我在pycharm中调试代码时,遇到以下错误。但是,代码在终端运行正常。
回溯(最近一次通话最近):文件“ /home/dj/tools/pycharm-2018.2.1/helpers/pydev/_pydevd_bundle/pydevd_comm.py”, _on_run中的第382行 r = r.decode('utf-8')文件“ /usr/lib/python2.7/encodings/init.py”,第134行,在 search_function (mod。名称,mod。文件)CodecRegistryError:模块“ encodings.utf_8”中的编解码器不兼容 (/usr/lib/python2.7/encodings/utf_8.pyc)
我的代码很简单:
# coding: utf-8
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
import shutil
import glob
import os
import random
def run():
src_dir = '/home/dj/result/'
dst_dir = '/home/dj/tmp/'
clear_paths = glob.glob(os.path.join(dst_dir, '*.jpg'))
for path in clear_paths:
os.remove(path)
all_paths = glob.glob(os.path.join(src_dir, '*.jpg'))
check_paths = random.sample(all_paths, 10)
for select_path in check_paths:
_, file_name = os.path.split(select_path)
save_path = os.path.join(dst_dir, file_name)
shutil.copy(select_path, save_path)
if __name__ == '__main__':
run()
我用谷歌搜索这个问题,但没有帮助。我该如何解决这个问题?
答案 0 :(得分:0)
我为自己回答。