diff --git a/spyderlib/userconfig.py b/spyderlib/userconfig.py index 30b2a53c863..90f3ecbc9d7 100644 --- a/spyderlib/userconfig.py +++ b/spyderlib/userconfig.py @@ -48,6 +48,8 @@ from spyderlib.py3compat import configparser as cp from spyderlib.py3compat import PY2, is_text_string, to_text_string +if PY2: + import codecs #============================================================================== # Auxiliary classes @@ -113,7 +115,7 @@ def _save(self): def _write_file(fname): if PY2: # Python 2 - with open(fname, 'w') as configfile: + with codecs.open(fname, 'w', encoding='utf-8') as configfile: self._write(configfile) else: # Python 3 @@ -251,7 +253,13 @@ def load_from_ini(self): try: if PY2: # Python 2 - self.read(self.filename()) + fname = self.filename() + if osp.isfile(fname): + try: + with codecs.open(fname, encoding='utf-8') as configfile: + self.readfp(configfile) + except IOError: + print("Failed reading file", fname) else: # Python 3 self.read(self.filename(), encoding='utf-8')