python - 模块“encodings.utf_8”中的编解码器不兼容
问题描述
当我在 pycharm 中调试我的代码时,我遇到了以下错误。但是,代码在终端中运行良好。
回溯(最近一次通话最后):文件“/home/dj/tools/pycharm-2018.2.1/helpers/pydev/_pydevd_bundle/pydevd_comm.py”,第 382 行,在 _on_run r = r.decode('utf-8' )文件“/usr/lib/python2.7/encodings/init .py”,第 134 行,在 search_function(mod.name,mod.file ) 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()
我用谷歌搜索了这个问题,但没有帮助。我怎么解决这个问题?
解决方案
我为自己回答。
- 实际上,我还没有解决方案。我的解决方案是重新安装 ubuntu 并安装 anaconda。
- 我认为这个问题的原因是python环境有问题。为了防止这种难以忍受的问题再次发生,我使用anaconda创建了多个python环境。
推荐阅读
- angular - 试图将布尔值从子组件传递给父组件
- java - 实现非常大的线程安全 HashMap
- sql - SQL世界数据库;查找至少有五个国家人口超过 1000 万的地区
- symfony - 翻译 Symfony 4 / twig
- python - 熊猫:在重复行时更改值
- c# - 计算旋转相机时保持对象居中所需的位置
- javascript - 返回一个由两个不同的 Observable 组成的合并对象,这些 Observable 依赖于 RxJS
- ionic-framework - 尝试从我的 API Ionic 4 获取值时出现问题
- python-3.x - Numpy数组和不同值的比较
- python - 将函数结果传递给 Django 中的 html