python3启动失败 Fatal Python error: initfsencoding: unable to load the file system codec

python2和python3同时存在时,其中一个启动失败,报错如下两种情况

 

1、python3启动失败,python2路径下文件报错

python3启动失败 Fatal Python error: initfsencoding: unable to load the file system codec_第1张图片

Fatal Python error: initfsencoding: unable to load the file system codec
  File "C:\Python27\Lib\encodings\__init__.py", line 123
    raise CodecRegistryError,\
                            ^
SyntaxError: invalid syntax

Current thread 0x000004dc (most recent call first):

2、python2启动失败,python3路径下文件报错

python3启动失败 Fatal Python error: initfsencoding: unable to load the file system codec_第2张图片

File "E:\Python37\Lib\site.py", line 177
    file=sys.stderr)
        ^
SyntaxError: invalid syntax

 

    上述两种情况根因相同,原因是设置了环境变量PYTHONPATH,PYTHONPATH是Python搜索路径,默认我们import的模块都会从PYTHONPATH里面寻找,环境变量设置为了其中某个版本的模块路径,导致另一个版本启动时模块加载路径出错,从而导致启动失败,这是按网上教程安装python时候留下的一个坑,其实这个变量可以不要,当自定义的模块不再python安装路径下时才需要配置改环境变量,所以可以把这个环境变量删掉,或者只删除C:\Pythonxx\Lib

python3启动失败 Fatal Python error: initfsencoding: unable to load the file system codec_第3张图片

删除后完美解决

python3启动失败 Fatal Python error: initfsencoding: unable to load the file system codec_第4张图片

你可能感兴趣的:(Python,配置)