Compile python code into a dll

  • Permalink
  • submit to reddit
  • Email
  • Follow


Hi,

I have Python code that I would like to compile into a dll (I have to 
deliver a C/C++ callable dll and I don't want to reimpelement the Python 
code in C/C++). It's not for extending Python but I want to call the 
Python functions and classes from C/C++. It's more like extending C/C++ 
with Python. I would be very appreciative for any help.

Thank you in advance

Regards
Rolf
0
Reply rolf.wester1 (24) 9/10/2012 12:15:03 PM

See related articles to this posting


On Monday, 10 September 2012 17:45:11 UTC+5:30, Rolf Wester  wrote:
> Hi,
> 
> 
> 
> I have Python code that I would like to compile into a dll (I have to 
> 
> deliver a C/C++ callable dll and I don't want to reimpelement the Python 
> 
> code in C/C++). It's not for extending Python but I want to call the 
> 
> Python functions and classes from C/C++. It's more like extending C/C++ 
> 
> with Python. I would be very appreciative for any help.
> 
> 
> 
> Thank you in advance
> 
> 
> 
> Regards
> 
> Rolf

http://docs.python.org/extending/embedding.html is the official docs for this thing
Embedding is similar to extending.
0
Reply maniandram01 (167) 9/10/2012 1:08:04 PM

> I have Python code that I would like to compile into a dll (I have to 
See http://docs.python.org/extending/embedding.html. You can pack your code in a zip file and load it from the DLL entry point (something like what py2exe does).

See also the Freeze tool - http://wiki.python.org/moin/Freeze.

HTH,
--
Miki (http://pythonwise.blogspot.com/)
0
Reply miki.tebeka (424) 9/10/2012 1:11:02 PM

On 9/10/2012 8:15 AM, Rolf Wester wrote:

> I have Python code that I would like to compile into a dll (I have to
> deliver a C/C++ callable dll and I don't want to reimpelement the Python
> code in C/C++). It's not for extending Python but I want to call the
> Python functions and classes from C/C++. It's more like extending C/C++
> with Python. I would be very appreciative for any help.

Cython compiles CPython to C which can be compiled by and c/c++ 
compiler. I believe it can do the above. "This makes Cython the ideal 
language for wrapping external C libraries, embedding CPython into 
existing applications, ". I think the latter is what you want to do.

http:cython.org

-- 
Terry Jan Reedy

0
Reply tjreedy (5459) 9/10/2012 4:06:42 PM

Thank you all for your help. I'm going to try Cython.

Regards
Rolf


On 10/09/12 14:15, Rolf Wester wrote:
> Hi,
>
> I have Python code that I would like to compile into a dll (I have to
> deliver a C/C++ callable dll and I don't want to reimpelement the Python
> code in C/C++). It's not for extending Python but I want to call the
> Python functions and classes from C/C++. It's more like extending C/C++
> with Python. I would be very appreciative for any help.
>
> Thank you in advance
>
> Regards
> Rolf

0
Reply rolf.wester1 (24) 9/11/2012 7:05:00 AM
comp.lang.python 72649 articles. 12 followers. Post

4 Replies
239 Views

Similar Articles

[PageSpeed] 35


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Modularizing wxwidgets code inside DLL(not compile wx dll)
hi I came across this old archive question http://lists.wxwidgets.org/archive/wx-users/msg24764.html reproduced below, and I have the exact same requirement. THIS IS NOT TO COMPILE WXWIDGET DLL but modularizing wx code within dlls Has somebody done this or can explain how to go about it?? Thx, >From archive: I have a main app (.exe) which uses wx :-) and some external modules implemented as DLLs. Each DLL exports two functions, to create and delete instances of a class derived from a common base class (mmm... I think this isn't relevant right now...). Then, each instance...

compiling python code
Hi, I have a python file inside a zip file. I'd like to compile it and add the resulting .pyc file into the zip. I tryed reading the source and compiling it using compile(), but I don't know how to write .pyc file. Can someone give me some help? bye, gabriele Gabriele *Darkbard* Farina wrote: > I have a python file inside a zip file. I'd like to compile it and add > the resulting .pyc file into the zip. I tryed reading the source and > compiling it using compile(), but I don't know how to write .pyc file. > Can someone give me some help? a PYC file consists ...

Creat a DLL File from python code, and use that DLL file in other Platform (Labview, Java .NET etc)
Hi, I would like to request your attention for this very specific issue: I have several classes in Python, and now I want simply re-use it, in other language. The closest to solution I think I came was with this site: http://www.py2exe.org/index.cgi/Py2exeAndCtypesComExeServer?highlight=%28%28Py2exeAndCtypesComDllServer%29%29 but I not able to solve questions related with TLB files and __init__.py files. So, could anyone give a tip about HOW TO CREAT a dll file from Python? thank in advance AMMS macedo.silva@gmail.com wrote: > Hi, > > I would like to request your attention ...

compiling to python byte codes
Hi, I remembered reading a MSc thesis about compiling Perl to Java bytecodes (as in java class files). At least, it seems that someone had compiled scheme to java class files quite successfully. I'm wondering if something of such had been attempted in python, as in compiling X language into .pyc. I do not understand the schematics of .pyc files but I assume that they are the so called python bytecode files. Or is there any documentation or books that is the python equivalent of "Programming for the Java Virtual Machine" by Joshua Engel? Thanks Maurice -- Maurice Han Ton...

Need compile python code
Need compile python code, source is in html and starts with parameters: #!/bin/sh - "exec" "python" "-O" "$0" "$@" I have installed ActivePython for windows. mistral wrote: > Need compile python code, source is in html and starts with > parameters: Excuse me? > #!/bin/sh - > "exec" "python" "-O" "$0" "$@" Is the line break intended? > I have installed ActivePython for windows. What exactly do you want? Python code is always compiled (to byte code) before it's run. ...

Compiling snippets of python code
I need some advice on compiling snippets of python source at runtime. So perhaps some python experts can point the way. I am rewriting an old Java app in python. It tries to find solutions to computational problems based on the idea of genetic evolution. The Java version just used an array of bytes for the genomes. These byte sequences were bytecode which told a rudimentary VM (virtual machine) which maths functions to call. It used another array as a small chunk of virtual memory for doing the calculations. Having seen the docs on python's compile module, I'm thinking of doing it d...

Serializing Python compiled code.
Hi everyone, In a C++ application having a Python interpreter embedded, is it possible to compile a small Python snippet into object code and serialize the compiled object code to, for example, a database? I am exploring the possibility of writing a data driven application, where small-sized object code can be read from a database and executed. Keeping aside all other considerations such as security, etc for a moment, is this feasible? Please do reply. Thanks, -/renji --- renjipanicker@gmail.com wrote: > In a C++ application having a Python interpreter > embedded, is it > possibl...

compiling c code to a dll
Hi, I want to compile a c file to a dll that I can use from matlab. I have been using shrlibsample.dll as an example. I can load the library and call the functions fine from the mathworks supplied dll. I used Visual C++ 6.0 to create my own dll using shrlibsample.c and shrlibsample.h as a prototype, and it creates the dll fine. But when I use loadlibrary from matlab, I get warning messages saying that the functions were not found in the library, and I can't view the functions. Can anyone advise me please? I also tried using mcc. Can anyone advise me on the switches I need to use to cre...

Translate code or compile a win DLL
Hi, i don't know perl but i need to use a script written in perl in the application i'm developping. Can i build it as DLL that exposes some functions so that i can use it? Orelse :D can somebody translate this code for me in C/C++/VB/C# or simply explain me what does it do? http://cpan.uwinnipeg.ca/htdocs/WWW-Google-PageRank/WWW/Google/PageRank.pm.html Thanks "VeNoM00" <venom.zero.zero@gmail.com> writes: > Hi, i don't know perl but i need to use a script written in perl in the > application i'm developping. > > Can i build it as DLL that expo...

Compiling Python code within a module
For various reason, what I need to do is be able to send some Python code (mostly entire functions in the form of a string) to a remote server (written in Python), have that server compile the code and insert it in the local namespace so it is available to be called at a later time. I have gotten the sending and receiving part already written and that works. However, I can't get the compiling part! I have looked at the compile module and while it is able to compile the code I am not entirely sure what to do with the returned code object so it get's inserted as a local function. I wou...

Compiling python scripts to native code ??
Hi... Is there any way to do this for *nix ?? Pointers to resources and/or FAQS would be much appreciated. Thanks, Fred. Fred Mailhot <fred.mailhot@videotron.ca> writes: > On 2/17/04 7:25 AM, "Thomas Guettler" <guettli@thomas-guettler.de> wrote: > > > Am Tue, 17 Feb 2004 08:43:15 -0800 schrieb Fred Mailhot: > > > >> Hi... > >> > >> Is there any way to do this for *nix ?? Pointers to resources and/or FAQS > >> would be much appreciated. > > > > Why do you want to do this? > > - Improve speed...

python compile code object -- reverse how to
Hi, following is the python scripts: import marshal script = """ print 'hello' """ code = compile(script, "<script>", "exec") data = marshal.dumps(code) print repr(data) the result:'c\000\000\000\000\001\000\000\000s\017\000\000\00 0\177\000\000\177\002\000d\000\000GHd\001\000S(\00 2\000\000\000s\005\000\000\000helloN(\000\000\000\ 000(\000\000\000\000s\010\000\000\000<script>s\001 \000\000\000?\002\000s\000\000\000\000'how to convert the result code to orig script """print 'hello'""...

Issues in compiling Python to machine code
I've been thinking about what the issues would be in compiling Python into native machine code, and since type information is important in Python, it seems possible that Python code can be compiled into native machine code (albeit with a lot of extra effort). For instance, type information is discovered when something is assigned to a variable or an anonymous piece of data is used in a program. Compiling Python bytecode into native machine code could involve a pass over the bytecode to look at all the uses of a variable or anonymous variable, call some Python function to discover its var...

dll errors in compiled python program
Hi all, I am stumped. The compiled version of my project works on my pc, but when I put it on a thumb drive and try it on a laptop without python installed I get this: Traceback (most recent call last): File "sw.pyw", line 3, in <module> File "modes\arm.pyc", line 4, in <module> File "dependencies\wmi1_3\wmi.pyc", line 140, in <module> File "win32com\__init__.pyc", line 5, in <module> File "win32api.pyc", line 12, in <module> File "win32api.pyc", line 10, in __load ImportError: DL...

can we compile java code into a dll?
I'm new to the world of Java programming..and interested to know whether Java code can be compiled into a Dll, so that it can be integrated with COM+ application(Windows Platform). Regards, Pramod Kumar Gujjeti On 18 Mar 2006 11:47:40 -0800, "pramod gujjeti" <pramod220@gmail.com> wrote, quoted or indirectly quoted someone who said : >I'm new to the world of Java programming..and interested to know >whether Java code can be compiled into a Dll, so that it can be >integrated with COM+ application(Windows Platform). you can with Jet. See http://mindprod.com...

compiling python source code under VC8
Hello everyone, I am trying to build python from scratch under VC8. The build process runs and completes succesfully in debug mode resulting in python_d.exe. But when i try to run this exe it returns an assertion error and application crashes. Has anyone successfully build python using VC8. Your help will be greatful. Thank You All > I am trying to build python from scratch under VC8. The build process > runs and completes succesfully in debug mode resulting in > python_d.exe. But when i try to run this exe it returns an assertion > error and application crashes. What Python ...

Need help: Compiling Python-Code
Hi, I wrote some little python programs which run without problems. Now I'd like to compile them into byte-code. What do I have to do? Platform: SuSE Linux 8.2 Thx in advance. Carsten ...

Creating a DLL file from Python Code
Hi, I would like to request your attention for this very specific issue: I have several classes in Python, and now I want simply re-use it, in other language. The closest to solution I think I came was with this site: http://www.py2exe.org/index.cgi/Py2exeAndCtypesComDllServer but I not able to solve questions related with TLB files and __init__.py files. So, could anyone give a tip about how to creat a dll file from Python? It is possible under any conditions? thank in advance macedo macedo.silva@gmail.com a �crit : > Hi, > > I would like to request your attention for this ...

RE: compiling to python byte codes
Leif K-Brooks wrote: > Jason Lai wrote: > [talking about compiling some language besides Python to=20 > Python bytecode] > > What about generating an Abstract Syntax Tree=20 > (compiler.ast) and using=20 > > the compiler module (compiler.pycodegen) to write the bytecode? >=20 > That would certainly be possible, but it seems to me like it might be=20 > easier to generate Python code. You're using Python logic if=20 > you use its AST, after all. In my limited experience, using compiler.ast ends up being *very* slow due to all of the tuple packing and unpa...

Compiling and Executing a Python byte coded program
If interested with, have a look to http://vouters.dyndns.org/tima/All-OS-Python-Compiling_a_Python_Program_and_Executing_the_compiled_version.html Note you may boost your Python's startup time but not the execution speed of your program which depends on the generated byte code. ...

Problem compiling C++ code with python embedded
Hello, I just recently switched my code from one server to another and now having some problems compiling my code. I was able to compile fine with my last server now but this current one is giving me problems. My build file is as follows g++ -Wall ibdws.cpp ../cgic205/cgic.c -oibdws.cgi -Lcgraph -lcgraph -Icgraph/Cgraph/source -I../cgic205 -L../cgic205 -I/usr/include/python2.4 -L/usr/lib /python2.4/site-packages -lpython2.4 However, the new server only has python 2.2 so i simply switched the 2.4 to 2.2 so now my build file looks like this: g++ -Wall ibdws.cpp ../cgic205/cgic.c -o...

RE: compiling to python byte codes #2
Maurice LING write: > I dont't quite get this right. Since x86/PPC uses register operations, > why do virtual machines, like python's and java's, are designed as > stack machines? Why not just stick to registers? Because it's much easier to code a stack-based VM, and also much easier to produce bytecode for a stack-based VM. Once you bring registers into the picture, the lovely, straightforward stack gets turned into a mess of which registers should be used when, etc. Tim Delaney ...

Re: Need help: Compiling Python-Code
import py_compile pycompile.compile(Python-file) Bye Thomas "Thomas Buschhardt" <thomas.buschhardt@iac-leipzig.de> wrote in message news:<mailman.1058258723.4935.python-list@python.org>... > import py_compile > pycompile.compile(Python-file) > > Bye Thomas I am sure the OP has a good reason for asking his question, nevertheless for the sake of newbies who wonder if they should byte-compile their scripts, here is an extract from help(py_compile): Note that it isn't necessary to byte-compile Python modules for execution efficiency -- Py...

compiling python (or ironpython) to .exe or .dll for or not for .NET
Hi python people, I am working with .NET (in C++/CLI and C#) but since I really love python I'd like to do things for .NET (or whatever) from python. Has anyone tried it? What (costless) compilers are good? Are there any (costless) editors like MS Visual Express you have tried? Is the newest Ironpython really as old as from 2004 July 28 (as stated on http://www.ironpython.com/)? Thanks. /Per Erik Strandberg yet another Fibonaccilover Il 28 Jun 2006 06:29:58 -0700, per9000 ha scritto: > Is the newest Ironpython really as old as from 2004 July 28 (as stated > on http://www.ir...