Python Forum
Py_Initialize Crash with Python 3.6
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Py_Initialize Crash with Python 3.6
#1
We have had Python 2.7 embedded in our software for some time. We have been going through the process of embedding Python 3.6. We have always relied on the user to be responsible for the installation of the full version of Python but this can have issues. We previously had an issue with 2.7 where if you called Py_Initialize and had no full version of Python installed then you encountered a Python fatal error. We got round this by using code similar to this:

Py_NoSiteFlag = 1;
NCString PyPrefix(Py_GetPrefix()); // This is just a native class of ours similar to CString
if (!PyPrefix.IsEmpty())
{
// If we have got this far then this indicates a full version of Python is present.
// This reinitialize after resetting the NoSiteFlag.
Py_Finalize();
Py_NoSiteFlag = 0;
Py_Initialize();
}

However after our switch to 3.6 the Python fatal error returns as it appears this NoSiteFlag fix doesn't work as you get a different Python fatal error in the first initialize call. I built the debug version of Python 3.6 and stepped into the Py_Initialize function. The fatal error now occurs in the following code:

if (initfsencoding(interp) < 0)
Py_FatalError("Py_Initialize: unable to load the file system codec");

This is because it cannot find a Python Lib folder I believe so cannot load the encodings. Looking at the code there doesn't appear to be any flags that can be set to avoid this.

I am looking for a solution where Py_Initialize doesn't fatal error on Python 3.6 when there isn't a full version of Python present. Pity the initialize function just doesn't return an error rather than throwing a fatal error then we could handle locally. I have read about having a embedded Python kit available locally if there isn't a full version present but we must be able to override this with a full version if one is installed. Any help on this would be appreciated.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Catching a crash within a library code ebolisa 9 3,069 Nov-22-2021, 11:02 AM
Last Post: bowlofred
  Python Crash Course ( 2nd edition) alok 1 1,844 Jul-19-2021, 05:55 PM
Last Post: snippsat
  Embedding python cause crash when use boost::asio multi threading udvatt108 0 1,695 Oct-04-2020, 03:15 PM
Last Post: udvatt108
  Im using python crash course version 2 james_newbie 3 2,347 Sep-07-2019, 09:21 PM
Last Post: ichabod801
  Python 3 crash course james_newbie 6 3,867 Aug-25-2019, 08:23 PM
Last Post: snippsat
  Pyinstaller exe won't launch after crash kainev 0 2,585 May-11-2019, 06:06 PM
Last Post: kainev
  Fatal Python error: Py_Initialize: unable to load the file system codec ecg1g15 0 3,535 Feb-12-2019, 12:16 PM
Last Post: ecg1g15
  python kernell crash with a ctypes program Jstechg 1 3,451 Nov-24-2018, 02:37 PM
Last Post: Jstechg
  IDLE crash using special characters? reikonaga 6 4,673 Aug-06-2018, 07:37 AM
Last Post: keegan_010
  How to Crash a Computer keegan_010 6 4,188 Aug-05-2018, 06:01 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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