Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying application with Python or another embedded scripting language

I'm thinking about using Python as an embedded scripting language in a hobby project written in C++. I would not like to depend on separately installed Python distribution. Python documentation seems to be quite clear about general usage, but I couldn't find a clear answer to this.

Is it feasible to deploy a Python interpreter + standard library with my application? Would some other language like Lua, Javascript (Spidermonkey), Ruby, etc. be better for this use?

Here's the criteria I'm weighing the different languages against:

  • No/Few dependencies on externally installed packages
  • Standard library with good feature set
  • Nice language :)
  • Doesn't result in a huge install package

edit:

I guess the question should be: How do I deploy my own python library + standard library with the installer of my program, so that it doesn't matter whether the platform already has python installed or not?

edit2:

One more clarification. I don't need info about specifics of linking C and Python code.

like image 776
John Smith Avatar asked Feb 15 '09 17:02

John Smith


People also ask

Is Python embedded scripting language?

Disadvantages: Python has a large footprint; it was not designed as an embedded scripting language and it is not possible to forbid the interpreter from calling file system and process creation APIs.

What is an embedded scripting language?

An embedded scripting language would be a scripting language (or more specifically an interpreter for such a language) that can be embedded into applications. Thus, the interpreter has an API that can be used to integrate it into the application, allowing scripts to control all or parts of the application.

What is embedded Python?

The simplest form of embedding Python is the use of the very high level interface. This interface is intended to execute a Python script without needing to interact with the application directly. This can for example be used to perform some operation on a file.


1 Answers

Link your application to the python library (pythonXX.lib on Windows) and add the following to your main() function.

Py_NoSiteFlag = 1;  // Disable importing site.py
Py_Initialize();    // Create a python interpreter

Put the python standard library bits you need into a zip file (called pythonXX.zip) and place this and pythonXX.dll beside the executable you distribute. Have a look at PyZipFile in the the zipfile module.

like image 177
James Emerton Avatar answered Oct 22 '22 05:10

James Emerton