【BUG】C++ Boost调用python报错:init

项目场景:

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


问题描述

使用visual studio 2019,配置好boost和python。

包含目录配置:

在这里插入图片描述

库目录配置:

在这里插入图片描述

测试后发现程序报错:

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的环境变量没有配置好。


解决方案:

根据提示:

在这里插入图片描述

可知:PYTHONHOME和PYTHONPATH没有配置。

打开系统属性——>环境变量——>系统变量:

建立PYTHONHOME和PYTHONPATH,路径名即为python的安装路径。

在这里插入图片描述

注意:如果python是基于Anaconda安装的,要取到envs下的各个python版本

本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://net2asp.com/e9afdc0d7c.html