Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 869691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:21:00+00:00 2026-05-15T10:21:00+00:00

I have an application where I’m embedding python. It was developed on windows where

  • 0

I have an application where I’m embedding python. It was developed on windows where it works fine, but now I’m porting it to linux with less success where it crashes in Py_Initialize(). From gdb, it seems to happen when loading the os module.

gdb reports this callstack on seg fault:

#0  0x002384fc in import_submodule (mod=None, subname=0xb7d8a9bb "os", fullname=0xb7d8a9bb "os") at ../Python/import.c:2551
#1  0x0023893c in load_next (mod=<value optimized out>, altmod=<value optimized out>, p_name=0xb7d8a9ac, buf=0xb7d8a9bb "os", p_buflen=0xb7d8a9b4) at ../Python/import.c:2411
//.... etc...:
#65 0x002439de in Py_Initialize () at ../Python/pythonrun.c:361

source code of import_submodule in Python/import.c (downloaded from 2.6.5 python):

static PyObject *
import_submodule(PyObject *mod, char *subname, char *fullname)
{ //***************** THIS IS LINE 2551***************************
    PyObject *modules = PyImport_GetModuleDict();
    PyObject *m = NULL;

    /* Require:
       if mod == None: subname == fullname
       else: mod.__name__ + "." + subname == fullname
    */

    if ((m = PyDict_GetItemString(modules, fullname)) != NULL) {
        Py_INCREF(m);
    }
    else {
        PyObject *path, *loader = NULL;
        char buf[MAXPATHLEN+1];
        struct filedescr *fdp;
        FILE *fp = NULL;

        if (mod == Py_None)
            path = NULL;
        else {
            path = PyObject_GetAttrString(mod, "__path__");
            if (path == NULL) {
                PyErr_Clear();
                Py_INCREF(Py_None);
                return Py_None;
            }
        }

        buf[0] = '\0';
        fdp = find_module(fullname, subname, path, buf, MAXPATHLEN+1,
                  &fp, &loader);
        Py_XDECREF(path);
        if (fdp == NULL) {
            if (!PyErr_ExceptionMatches(PyExc_ImportError))
                return NULL;
            PyErr_Clear();
            Py_INCREF(Py_None);
            return Py_None;
        }
        m = load_module(fullname, fp, buf, fdp->type, loader);
        Py_XDECREF(loader);
        if (fp)
            fclose(fp);
        if (!add_submodule(mod, m, fullname, subname, modules)) {
            Py_XDECREF(m);
            m = NULL;
        }
    }

    return m;
}

Disassembly + part source + breakpoint:

2550    import_submodule(PyObject *mod, char *subname, char *fullname)
2551    {
   0x002384f0 <+0>: push   %ebp
   0x002384f1 <+1>: mov    %esp,%ebp
   0x002384f3 <+3>: sub    $0x1058,%esp
   0x002384f9 <+9>: mov    %ebx,-0xc(%ebp)
=> 0x002384fc <+12>:    call   0x174787 <__i686.get_pc_thunk.bx>
   0x00238501 <+17>:    add    $0x112af3,%ebx
   0x00238507 <+23>:    mov    %esi,-0x8(%ebp)
   0x0023850a <+26>:    mov    0x8(%ebp),%esi
   0x0023850d <+29>:    mov    %edi,-0x4(%ebp)
   0x00238510 <+32>:    mov    %eax,-0x102c(%ebp)
   0x00238516 <+38>:    mov    %edx,-0x1030(%ebp)
   0x0023851c <+44>:    mov    %gs:0x14,%eax

What’s happening here? Apparently some code from libpython2.6.so is loaded and run.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:21:00+00:00Added an answer on May 15, 2026 at 10:21 am

    Try setting the Python home with Py_SetPythonHome before calling Py_Initialize. Start with hardcoded complete path to the python directory. Also make sure you are not mixing debug & release versions. Py_GetPath is a good API to see where all python is looking for modules – but dont know if it can be called before Py_Initialize.

       char pySearchPath[] = "/users/abc/Python26";
       Py_SetPythonHome(pySearchPath);
       Py_Initialize();
       PyRun_SimpleString("from time import time,ctime\n"
                         "print 'Today is',ctime(time())\n");
       cerr << Py_GetPath() << endl;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 443k
  • Answers 443k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Well, xs:any can be anything, so the best the .NET… May 15, 2026 at 6:13 pm
  • Editorial Team
    Editorial Team added an answer Got it! solution Clojure is not motivated to run the… May 15, 2026 at 6:13 pm
  • Editorial Team
    Editorial Team added an answer I'm not sure if this is what you want, but… May 15, 2026 at 6:13 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.