The problem is a bit more specific. I am using the 3.3.3 version of Python and have built it myself. When I embed it into my program _Py_InitializeEx_Private()
exits with this error Py_Initialize: can't initialize sys standard streams
这个问题有点具体。我正在使用3.3.3版本的Python并自己构建它。当我将它嵌入我的程序_Py_InitializeEx_Private()退出时出现此错误Py_Initialize:无法初始化sys标准流
Background: I'm using Visual Studio 2012 Express and am starting Python in a boost thread. Boiled down, the call looks like that:
背景:我正在使用Visual Studio 2012 Express并在boost线程中启动Python。煮熟了,电话看起来像这样:
int SubSysPython::Start()
{
m_PythonThread = boost::thread(&SubSysPython::StartPython, this);
return m_RC;
}
void SubSysPython::StartPython()
{
Py_Initialize();
FILE* fp = nullptr;
fopen_s(&fp, startScript.c_str(), "r");
PyRun_SimpleFile(fp, startScript.c_str());
fclose(fp);
Py_Finalize();
}
The libraries are copied from the working build, the python lib folder is original (copy from the 3.3.3 binary dist). I tried to trace down the problem in the debugger, but I failed to understand the python internals in a reasonable time.
库是从工作版本复制的,python lib文件夹是原始的(从3.3.3二进制文件复制)。我试图在调试器中追查问题,但我在合理的时间内无法理解python内部。
Does someone have any ideas what could be the cause? I suppose it's just a minor problem I'm not aware of but I'm a bit short on options at the moment..
有人有什么想法可能是什么原因?我想这只是一个我不知道的小问题,但我现在的选项有点短暂..
1 个解决方案
#1
0
There is a Python ticket to this problem. Somehow I failed to find it first time but it's definitely relevant. The streams are bugged in non-terminal applications. It may be fixed in the Python code with:
这个问题有一张Python票。不知怎的,我第一次没能找到它,但它绝对相关。这些流在非终端应用程序中被窃听。它可以在Python代码中修复:
#ifdef MS_WINDOWS
if (!is_valid_fd(fd) || GetStdHandle(STD_INPUT_HANDLE) == NULL) {
#else
if (!is_valid_fd(fd)) {
#endif
at the !is_valid_fd() passages.
在!is_valid_fd()段落。
The ticket may be found here: Issue17797
门票可在此处找到:Issue17797
#1
0
There is a Python ticket to this problem. Somehow I failed to find it first time but it's definitely relevant. The streams are bugged in non-terminal applications. It may be fixed in the Python code with:
这个问题有一张Python票。不知怎的,我第一次没能找到它,但它绝对相关。这些流在非终端应用程序中被窃听。它可以在Python代码中修复:
#ifdef MS_WINDOWS
if (!is_valid_fd(fd) || GetStdHandle(STD_INPUT_HANDLE) == NULL) {
#else
if (!is_valid_fd(fd)) {
#endif
at the !is_valid_fd() passages.
在!is_valid_fd()段落。
The ticket may be found here: Issue17797
门票可在此处找到:Issue17797