Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding

问题

按python3 回车
无法使用

root@autodl-container-c6d211bb3c-2ce423ea:/usr/local/python-3.8.1/bin# python3
Python path configuration:
  PYTHONHOME = '/etc'
  PYTHONPATH = ':/usr/local/python-2.7.9/lib/python2.7:/usr/local/python-3.8.1/lib/python3.8'
  program name = 'python3'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = '/usr/local/python-3.8.1/bin/python3'
  sys.base_prefix = '/etc'
  sys.base_exec_prefix = '/etc'
  sys.executable = '/usr/local/python-3.8.1/bin/python3'
  sys.prefix = '/etc'
  sys.exec_prefix = '/etc'
  sys.path = [
    '',
    '/usr/local/python-2.7.9/lib/python2.7',
    '/usr/local/python-3.8.1/lib/python3.8',
    '/etc/lib/python38.zip',
    '/etc/lib/python3.8',
    '/etc/lib/python3.8/lib-dynload',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
  File "/usr/local/python-2.7.9/lib/python2.7/encodings/__init__.py", line 123
    raise CodecRegistryError,\
                            ^
SyntaxError: invalid syntax

Current thread 0x00007f970333e280 (most recent call first):
<no Python frame>

原因

python3的PYTHONPATH不对
我的PYTHONPATH有两个,
前面一个是python2.7.9的,
它先调用了python2.7.9的,
没调用3.8.1的,
所以报错

解决

清掉原来的PYTHONPATH
设置新的,
赋值为3.8.1的路径

root@autodl-container-c6d211bb3c-2ce423ea:/usr/local/python-3.8.1/bin# unset PYTHONPATH
root@autodl-container-c6d211bb3c-2ce423ea:/usr/local/python-3.8.1/bin# export PYTHONPATH=$PYTHONPATH:/usr/local/python-3.8.1/lib/python3.8
root@autodl-container-c6d211bb3c-2ce423ea:/usr/local/python-3.8.1/bin# python3
Python 3.8.1 (default, Feb  8 2023, 15:33:21) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

缺点是python2.7.9不能用了,
具体表现是输入python回车会报错,
如果要用的话,
要把PYTHONPATH改回2.7.9的

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误通常表示Python无法找到文件系统编码的编解码器。根据引用和引用,这个错误可能是由于Python环境配置问题引起的。可能是PYTHONPATH或PYTHONHOME变量没有正确配置,导致Python无法找到所需的模块或编解码器。另外,引用中提到的错误也与环境变量配置有关。 为了解决这个问题,你可以尝试以下几个步骤: 1. 检查PYTHONPATH和PYTHONHOME变量的配置是否正确。确保它们指向正确的Python安装目录和库路径。 2. 如果你在使用虚拟环境,确保虚拟环境的配置正确,并且PYTHONPATH和PYTHONHOME变量指向了该虚拟环境的路径。 3. 确保你的Python安装完整且没有损坏。你可以尝试重新安装Python,并使用官方的安装程序来确保正确配置环境变量和路径。 如果以上步骤都不能解决问题,你可能需要查看更详细的错误信息以找出根本原因。你可以在Python命令行或脚本中加入调试语句,如打印sys.path来查看Python的搜索路径是否正确。如果问题仍然存在,你可以尝试在Python的官方论坛或相关的技术社区上寻求帮助,以获取更具体的指导。 总之,Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding Python runtime state: core initialized的错误通常是由于Python环境配置问题引起的。检查并正确配置PYTHONPATH和PYTHONHOME变量,确保Python安装完整且没有损坏可能有助于解决这个问题。123 #### 引用[.reference_title] - *1* *2* [invalid python sd,Fatal Python error: init_fs_encoding: failed to get the Python cod如何解决](https://blog.csdn.net/weixin_44216436/article/details/119947542)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] - *3* [已解决Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem ...](https://blog.csdn.net/weixin_45347379/article/details/120279256)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值