embed python dynamically

Discussion in 'Python' started by naveen, Nov 26, 2009.

  1. naveen

    naveen Guest

    How do you embed the python dll file distributed with the automatic
    installable python distribution on windows?
    Is it possible to dynamically load the python dll from running c
    program and start up a python interpreter ?
    Do you have to compile python from source to be able to embed python?
    naveen, Nov 26, 2009
    #1
    1. Advertising

  2. naveen

    naveen Guest

    Re: embed installed python dynamically

    ok, it was almost intuitive.
    just made a simple visual c express dll project
    included python26\include and python26\libs in the project settings
    the debug version has issues, but the release compiles without a
    problem.
    here is the source:
    http://github.com/tinku99/embedpython
    naveen, Nov 26, 2009
    #2
    1. Advertising

  3. naveen

    naveen Guest

    Re: embed installed python dynamically

    ok, its even easier than that.
    With autohotkey:

    pythondll := DllCall("LoadLibrary", "str", "c:\windows
    \system32\python26.dll")
    init := DllCall("c:\windows\system32\python26.dll\Py_Initialize"
    , "Cdecl")
    msgbox python initalized
    call := DllCall("c:\windows\system32\python26.dll\PyRun_SimpleString"
    , "str", "import sys", "Cdecl")
    msgbox will exit using python code
    call := DllCall("c:\windows\system32\python26.dll\PyRun_SimpleString"
    , "str", "sys.exit(0)", "Cdecl")
    init := DllCall("c:\windows\system32\python26.dll\Py_Finalize"
    , "Cdecl")
    msgbox % never called
    naveen, Nov 26, 2009
    #3
    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. Martin
    Replies:
    2
    Views:
    823
    Martin
    Dec 16, 2003
  2. disgracelands

    Trying to embed python into C, help!

    disgracelands, Aug 10, 2003, in forum: Python
    Replies:
    2
    Views:
    364
    Syver Enstad
    Aug 10, 2003
  3. Tommy Ryding

    Embed Python

    Tommy Ryding, May 17, 2005, in forum: Python
    Replies:
    0
    Views:
    368
    Tommy Ryding
    May 17, 2005
  4. kyo guan

    profile python in embed system

    kyo guan, May 23, 2005, in forum: Python
    Replies:
    0
    Views:
    375
    kyo guan
    May 23, 2005
  5. Wezzy
    Replies:
    2
    Views:
    355
    Wezzy
    Aug 28, 2005
Loading...

Share This Page