【问题标题】:incompatible codecs in module "encodings.utf_8"模块“encodings.utf_8”中的编解码器不兼容
【发布时间】:2019-05-02 04:27:54
【问题描述】:

当我在 pycharm 中DEBUG我的代码时,我遇到了以下错误。但是,代码在终端中运行良好。

Traceback(最近一次调用最后一次):文件“/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 行,在 搜索功能 (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()

我用谷歌搜索了这个问题,但没有帮助。我该如何解决这个问题?

【问题讨论】:

  • 错误!= 代码示例。检查 pycharm 调试器,例如取消选中“收集运行时类型信息以获取代码洞察力”选项。 intellij-support.jetbrains.com/hc/en-us/community/posts/…
  • 感谢您的回答。我尝试选择或取消选择该选项,但没有帮助。 @伴侣
  • 你试过用pycharm运行它吗?
  • 去掉顶部的# coding: utf-8魔术评论有用吗?
  • 代码在终端中运行良好。 @伴侣

标签: python pycharm


【解决方案1】:

我自己回答。

  • 实际上,我还没有解决方案。我的解决方案是重新安装 ubuntu 并安装 anaconda。
  • 我认为这个问题的原因是python有问题 环境。为了防止这种难以忍受的问题再次发生,我使用 anaconda 创建多个 python 环境。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-16
    • 2010-10-19
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多