problem with embedding python 2.3 and importing win32 extensions

Discussion in 'Python' started by Axel Diener, Feb 11, 2004.

  1. Axel Diener

    Axel Diener Guest

    I embed python interpreters in a C++ program.
    For each script to execute I create a new interpreter.
    In this environment I can use the win32 extensions only one time.
    Here is a little piece of code to illustrate the problem:

    int
    main(int argc, char **argv)
    {
    Py_Initialize();
    Py_SetProgramName(argv[0]);

    PyThreadState *save_tstate=PyThreadState_Swap(NULL);
    PyThreadState *state=Py_NewInterpreter();

    int rc=PyRun_SimpleString("import pywintypes;import pythoncom");
    //this works well
    printf("%d\n",rc);

    Py_EndInterpreter(state);

    PyThreadState_Swap(save_tstate);

    state=Py_NewInterpreter();

    rc=PyRun_SimpleString("import pywintypes;import pythoncom");
    //this and all further atemps will fail
    printf("%d\n",rc);

    Py_EndInterpreter(state);
    PyThreadState_Swap(save_tstate);

    Py_Finalize();
    }

    Here is the output auf this little program:

    0
    Traceback (most recent call last):
    File "<string>", line 1, in ?
    File "C:\uti\Python23\Lib\site-packages\pythoncom.py", line 3, in ?
    pywintypes.__import_pywin32_system_module__("pythoncom", globals())
    File "C:\uti\Python23\Lib\site-packages\win32\lib\pywintypes.py", line
    9, in _
    _import_pywin32_system_module__
    import imp, sys, os
    TypeError: 'NoneType' object is not callable
    -1

    I use

    Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on win32

    with

    pywin32-200.win32-py2.3.exe
    (same result for win32all-163)

    The problem doesn't occur with Python 2.2 and win32all-157 due to different
    import wrappers.

    Is there any way to overcome this problem?

    Thanks
    Axel Diener
    Axel Diener, Feb 11, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. stefan
    Replies:
    3
    Views:
    436
    stefan
    Dec 8, 2004
  2. Mudcat
    Replies:
    4
    Views:
    1,112
    John Machin
    Apr 21, 2005
  3. moerchendiser2k3

    Python Embedding Importing relative modules

    moerchendiser2k3, Jul 6, 2010, in forum: Python
    Replies:
    7
    Views:
    486
  4. Phil Tomson

    embedding, 'require' and extensions

    Phil Tomson, Oct 30, 2004, in forum: Ruby
    Replies:
    3
    Views:
    114
  5. Remi Gillig

    Loading extensions and embedding

    Remi Gillig, Jun 9, 2008, in forum: Ruby
    Replies:
    0
    Views:
    84
    Remi Gillig
    Jun 9, 2008
Loading...

Share This Page