Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem in Py_Initialize
#1
Hello,
I'm trying to use Python API in a C++ program.
I have downloaded source files of Python 3.4.4 and I have compiled them with Microsoft Visual C++ 2010.

In my project (Application console), I just include Python.h and try to call Py_Initialize() :

#include "stdafx.h"

#include <Python.h>

int _tmain(int argc, _TCHAR* argv[])
{
    Py_Initialize();
    Py_Finalize();

    return 0;
}
This initialization aborts because of this error :
"Fatal Python error: Py_Initialize: unable to load the file system codec"

I do not use other version of Python on the computer.
I have spent lots of time to find a solution online but I cannot find a begining of solution.

Would someone have an idea ? some actions to make in order to reduce the scope of the problem ?

Where can I check the existence of "file system codec ?" ? are they file on disk ? if yes where ?

Thanks by advance for the help,
Julien
Reply
#2
There is a tutorial here: http://realmike.org/blog/2012/07/08/embe...al-part-1/
At the start of the tutorial, there's a small example.
Try that and if it runs use it as a template.
I noticed it includes string.h and iostream.h but doubt that that would be an issue for you.
Reply
#3
Thanks for your answer.

This morning I have looked more deeply for the cause of my problem and I have followed the idea that consists in comparing the debug of python_d.exe initialization and the one of my test project. It results that initialization needs stuff in PYTHONHOME\Lib to succeed. In my case, the calculate_path function does not encounter any PYTHONHOME content and consider that the encodings files are in ".\Lib" but I have not such a folder in my executable path that explains why I had the error (for python_d.exe, the executable is in an official Python folder tree, and calculate_path() considers that the Lib folder is there, and it is ! so it's working)

Solution I have set up : If no PYTHONHOME is defined, I define it with my executable path after having checked that there is a Lib\extensions folder in it. At install time, I'll deliver in .\Lib and .\Lib extensions the minimum files required to initialize correctly with Py_Initialize().

Hope this can help  Shy ,

Julien
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Fatal Python error: Py_Initialize: unable to load the file system codec ecg1g15 0 3,557 Feb-12-2019, 12:16 PM
Last Post: ecg1g15
  Py_Initialize Crash with Python 3.6 paulhbm 0 4,379 Sep-20-2018, 09:56 AM
Last Post: paulhbm

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020