diff --git a/IPython/utils/path.py b/IPython/utils/path.py index a5e6db2..32b4b13 100644 --- a/IPython/utils/path.py +++ b/IPython/utils/path.py @@ -441,8 +441,12 @@ def ensure_dir_exists(path, mode=0o755): try: path_exists = os.path.exists(path) except UnicodeEncodeError: - path = path.encode(sys.getfilesystemencoding() or "utf8") - path_exists = os.path.exists(path) + try: + path = path.encode(sys.getfilesystemencoding() or "utf8") + path_exists = os.path.exists(path) + except UnicodeEncodeError: + path = path.encode("utf8") + path_exists = os.path.exists(path) if not os.path.exists(path): try: