ITPub博客

首页 > IT职业 > IT图书 > anaconda spyder出错解决方法

anaconda spyder出错解决方法

IT图书 作者:luckybird 时间:2021-09-11 10:21:25 0 删除 编辑

anaconda spyder出错解决:(推荐:anaconda使用教程)

写Python程序时突然遇到报错:

This command failed to be executed because an error occurred while trying to get the file code from Spyder's editor. The error was:


An exception has occurred, use %tb to see the full traceback.

UnicodeDecodeError: 'gbk' codec can't decode byte 0x93 in position 582: illegal multibyte sequence

UnicodeDecodeError: 'gbk' codec can't decode byte 0x93 in position 611: illegal multibyte sequence

In [2]: %tb
Traceback (most recent call last):

  File "C:UserspeterAnaconda3libsite-packagesspyder_kernelscustomizespydercustomize.py", line 401, in get_file_code
    return f.read()

UnicodeDecodeError: 'gbk' codec can't decode byte 0x93 in position 582: illegal multibyte sequence

先尝试重启程序,也许报错就解决了。

解决方法是根据报错,修改文件C:UserspeterAnaconda3libsite-packagesspyder_kernelscustomizespydercustomize.py为:

def get_file_code(filename):
    """Retrive the content of a file."""
    # Get code from spyder
    try:
        file_code = frontend_request().get_file_code(filename)
    except (CommError, TimeoutError):
        file_code = None
    if file_code is None:
        with open(filename, 'r',encoding='utf-8') as f:#增加 ,encoding='utf-8'
            return f.read()
    return file_code

如果不重启程序,会报错:

[autoreload of spydercustomize failed: Traceback (most recent call last):
  File "C:UserspeterAnaconda3libsite-packagesIPythonextensionsautoreload.py", line 245, in check
    superreload(m, reload, self.old_objects)
  File "C:UserspeterAnaconda3libsite-packagesIPythonextensionsautoreload.py", line 394, in superreload
    module = reload(module)
  File "C:UserspeterAnaconda3libimp.py", line 314, in reload
    return importlib.reload(module)
  File "C:UserspeterAnaconda3libimportlib__init__.py", line 168, in reload
    raise ModuleNotFoundError(f"spec not found for the module {name!r}", name=name)
ModuleNotFoundError: spec not found for the module 'spydercustomize'
]
This command failed to be executed because an error occurred while trying to get the file code from Spyder's editor. The error was:


An exception has occurred, use %tb to see the full traceback.

UnicodeDecodeError: 'gbk' codec can't decode byte 0x93 in position 582: illegal multibyte sequence

更多python知识请关注python视频教程。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1377/viewspace-2834464/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    113
  • 访问量
    1389