dj.lee
dj.lee

Reputation: 31

incompatible codecs in module "encodings.utf_8"

When I DEBUG my code in pycharm, I meet the error below. However, the code is running fine in terminal.

Traceback (most recent call last): File "/home/dj/tools/pycharm-2018.2.1/helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 382, in _on_run r = r.decode('utf-8') File "/usr/lib/python2.7/encodings/init.py", line 134, in search_function (mod.name, mod.file) CodecRegistryError: incompatible codecs in module "encodings.utf_8" (/usr/lib/python2.7/encodings/utf_8.pyc)

my code is simple:

# 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()

I google this question but not help. How can I solve this problem?

Upvotes: 0

Views: 1291

Answers (1)

dj.lee
dj.lee

Reputation: 31

I answer for myself.

  • Actually, I don't have a solution yet. My solution is re-install ubuntu and install anaconda.
  • I think the reason of this problem is something wrong with the python environment. To prevent this unbearable problem happen again, I use anaconda to create multiple python environment.

Upvotes: 1

Related Questions