Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]

  • Post author:
  • Post category:python


记录备忘.

1.完整报错信息

Could not find platform independent libraries <prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007f5ab301f6c0 (most recent call first):

2.报错原因

场景是C++调用python时,找不到python解释器。

3.解决办法

在init之前添加解释器位置说明。

Py_SetPythonHome(L"/home/zxq/anaconda3/envs/onnx");

# 再去初始化
Py_Initialize();

printf("Python init \n");


Py_Finalize();



版权声明:本文为jizhidexiaoming原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。