Python 模块中的编解码器不兼容“;编码.utf_8“;
当我在pycharm中调试我的代码时,我遇到以下错误。然而,代码在终端中运行良好 回溯(最近一次调用):文件“/home/dj/tools/pycharm-2018.2.1/helpers/pydev/_-pydev\u bundle/pydevd\u comm.py”, 第382行,正在运行 r=r.decode('utf-8')文件/usr/lib/python2.7/encodings/init.py”,第134行,在 搜索函数 (mod.名称,mod.文件)编解码器注册错误:模块“encodings.utf_8”中的编解码器不兼容 (/usr/lib/python2.7/encodings/utf_8.pyc) 我的代码很简单:Python 模块中的编解码器不兼容“;编码.utf_8“;,python,pycharm,Python,Pycharm,当我在pycharm中调试我的代码时,我遇到以下错误。然而,代码在终端中运行良好 回溯(最近一次调用):文件“/home/dj/tools/pycharm-2018.2.1/helpers/pydev/_-pydev\u bundle/pydevd\u comm.py”, 第382行,正在运行 r=r.decode('utf-8')文件/usr/lib/python2.7/encodings/init.py”,第134行,在 搜索函数 (mod.名称,mod.文件)编解码器注册错误:模块“enc
# 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()
我用谷歌搜索这个问题,但没有帮助。我怎样才能解决这个问题?我自己回答
- 事实上,我还没有解决办法。我的解决方案是重新安装 ubuntu并安装anaconda
- 我认为这个问题的原因是python有问题 环境为了防止这个无法忍受的问题再次发生,我使用 anaconda创建多个python环境
#coding:utf-8
魔术注释,它是否有效?代码在终端中运行良好@伴侣