"D:\...Climb_C_site\venv\Scripts\python.exe" "D:\...\Small_Case\change_suffix.py" Fatal Python error: initfsencoding: unable to load the file system codec ModuleNotFoundError: No module named 'encodings' Current thread 0x00000114 (most recent call first): Process finished with exit code -1073740791 (0xC0000409) Fatal Python error: initfsencoding: unable to load the file system codec ModuleNotFoundError: No module named 'encodings' Current thread 0x00001730 (most recent call first): 部分代码:
"D:\...Climb_C_site\venv\Scripts\python.exe" "D:\...\Small_Case\change_suffix.py" 这里环境变量设置为了其中某个模块路径,导致另一个模块运行加载路径出错,从而导致运行失败。
cmd查询当前python路径python -m siteview->Tool Windows->Terminal(pytharm里打开cmd)File -> Settings -> project:pycharmproject -> project interpreter
部分代码:
def change_suffix(): old_file_name_list = [] start_time = time.time() print("ok") end_time = time.time() print("此次用时 %s" % (end_time-start_time)) 结果就会输出
ok 当出现这个问题是基本上就是环境变量的问题了,那么你可以去环境变量中删除即可,我这里是因为在系统环境变量中加了,系统的环境变量优先级要高于用户变量,在系统环境中删除后,添加到了用户变量的python环境的后面。
如果不同于这篇安装python来安装python的话很多会让你设置一个环境变量为PYTHONPATH,但是这个变量其实也可以不需要,当自定义的模块不再python安装路径下时才需要配置改环境变量,所以可以把这个环境变量删掉,或者只删除C:\Pythonxx\Lib。
下一篇:【Python】成功解决Python报错:ImportError: cannot import name ‘xxx‘ from partially initialized module ‘yyy‘