【BUG】C++ Boost调用python报错:init_fs_encoding:failed to get the Python codec of the file

项目场景:

使用python sklearn训练模型,C++ boost加载模型脚本文件。


问题描述

使用visual studio 2019,配置好boost和python。
包含目录配置:
【BUG】C++ Boost调用python报错:init_fs_encoding:failed to get the Python codec of the file_第1张图片
库目录配置:
【BUG】C++ Boost调用python报错:init_fs_encoding:failed to get the Python codec of the file_第2张图片
测试后发现程序报错:
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named ‘encodings’


原因分析:

原因是python的环境变量没有配置好。


解决方案:

根据提示:
【BUG】C++ Boost调用python报错:init_fs_encoding:failed to get the Python codec of the file_第3张图片
可知:PYTHONHOME和PYTHONPATH没有配置。
打开系统属性——>环境变量——>系统变量:
建立PYTHONHOME和PYTHONPATH,路径名即为python的安装路径。
【BUG】C++ Boost调用python报错:init_fs_encoding:failed to get the Python codec of the file_第4张图片
注意:如果python是基于Anaconda安装的,要取到envs下的各个python版本

你可能感兴趣的:(BUG记录,c++,python,开发语言)