安装Anaconda安装后,启动Spyder报错:UnicodeDecodeError: ‘utf-8‘ codec can‘t decode

一、问题:

更新Spyer后启动报错,未能解决,重装Anaconda。
重装后,点击Spyder图标启动失败,进入Anaconda Prompt启动,报错如下。

(base) C:\windows\system32>spyder
fromIccProfile: failed minimal tag size sanity
F:\Anaconda\lib\site-packages\paramiko\transport.py:219: CryptographyDeprecationWarning: Blowfish has been deprecated
  "class": algorithms.Blowfish,
Traceback (most recent call last):
  File "F:\Anaconda\Scripts\spyder-script.py", line 10, in 
    sys.exit(main())
  File "F:\Anaconda\lib\site-packages\spyder\app\start.py", line 252, in main
    mainwindow.main(options, args)
  File "F:\Anaconda\lib\site-packages\spyder\app\mainwindow.py", line 1822, in main
    mainwindow = create_window(MainWindow, app, splash, options, args)
  File "F:\Anaconda\lib\site-packages\spyder\app\utils.py", line 289, in create_window
    main.setup()
  File "F:\Anaconda\lib\site-packages\spyder\app\mainwindow.py", line 773, in setup
    PLUGIN_REGISTRY.register_plugin(self, PluginClass,
  File "F:\Anaconda\lib\site-packages\spyder\api\plugin_registration\registry.py", line 342, in register_plugin
    instance = self._instantiate_spyder5_plugin(
  File "F:\Anaconda\lib\site-packages\spyder\api\plugin_registration\registry.py", line 184, in _instantiate_spyder5_plugin
    plugin_instance = PluginClass(main_window, configuration=CONF)
  File "F:\Anaconda\lib\site-packages\spyder\api\plugins\new_api.py", line 331, in __init__
    container.setup()
  File "F:\Anaconda\lib\site-packages\spyder\plugins\pythonpath\container.py", line 55, in setup
    self._load_pythonpath()
  File "F:\Anaconda\lib\site-packages\spyder\plugins\pythonpath\container.py", line 136, in _load_pythonpath
    system_path = get_system_pythonpath()
  File "F:\Anaconda\lib\site-packages\spyder\plugins\pythonpath\utils.py", line 31, in get_system_pythonpath
    env = get_user_env()
  File "F:\Anaconda\lib\site-packages\spyder\utils\environ.py", line 71, in get_user_env
    env_dict = get_user_environment_variables()
  File "F:\Anaconda\lib\site-packages\spyder\utils\environ.py", line 60, in get_user_environment_variables
    res = stdout.decode().strip().split(os.linesep)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb3 in position 662: invalid start byte

二、解决

1.分析报错

(1)报错代码的最后一行:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb3 in position 662: invalid start byte

由于解码的问题导致报错。

(2)报错位置

File "F:\Anaconda\lib\site-packages\spyder\utils\environ.py", line 60, in get_user_environment_variables
    res = stdout.decode().strip().split(os.linesep)

文件夹:F:\Anaconda\lib\site-packages\spyder\utils
文件名:environ.py
所在行:line 60
代码行:res = stdout.decode().strip().split(os.linesep)

2.解决方法

安装Anaconda安装后,启动Spyder报错:UnicodeDecodeError: ‘utf-8‘ codec can‘t decode_第1张图片
(1)打开报错文件
environ.py
(2)找到报错代码行
line 60
res = stdout.decode().strip().split(os.linesep)
(3)修复报错代码
res = stdout.decode(‘gbk’).strip().split(os.linesep)
(4)保存文件
保存更改后的environ.py,然后退出关闭,重启Spyder。

三、 注意事项

报错代码开头:
UnicodeDecodeError: ‘utf-8’ codec can’t decode
具体报错位置:
byte 0xb3 in position 662: invalid start byte

问题大类都是UnicodeDecodeError,每个个案的细节 byte 0xb3 in position 662可能有所不同,找到你的代码的报错位置,修改对应的报错代码。不要照搬代码,那样解决不了你遇到的问题。

你可能感兴趣的:(python,windows,开发语言)