Note that there are some explanatory texts on larger screens.

plurals
  1. POThe "right" way to add python scripting to a non-python application
    text
    copied!<p>I'm currently in the process of adding the ability for users to extend the functionality of my desktop application (C++) using plugins scripted in python.</p> <p>The naive method is easy enough. Embed the python static library and follow any number of the dozens of tutorials scattered around the web describing how to initialize and call python files, and you're pretty much done.</p> <p>However...</p> <p>What I'm looking for is more like what <a href="http://www.blender.org/" rel="noreferrer">Blender</a> does. Blender is completely customizable through python scripts, and it requires an <em>external</em> python executable. (Ie. python isn't actually <strong>embedded</strong> in the blender executable at all.) So, naturally, you can include any modules you already have in your site-packages directory when you are writing blender scripts. Not that that's advised, since that would limit the portability of your script.</p> <p>So, what I want to know is if there is already a way to have your cake and eat it too. I want a plugin system that uses:</p> <ul> <li><p>An embedded python interpreter.</p> <p>The downside of Blender's approach is that it forces you to have a specific, possibly outdated version of python installed globally on your system. Having an embedded interpreter allows me to control what version of python is being used.</p></li> <li><p>Firewall plugins.</p> <p>Some equivalent of a <code>virtualenv</code> for each plugin; allowing them to install all the modules they need or want, but keeping them seperated from possible conflicts in other plugins. Maybe <code>zc.buildout</code> is a better candidate here, but, again, I'm <strong>very</strong> open to suggestion. I'm a bit at a loss as to the best way to accomplish this.</p></li> <li><p>As painless as possible...</p> <p>For the user. I'm willing to go the extra mile, just so long as most of the above is as transparent to the plugin writer as possible.</p></li> </ul> <hr> <p>If any of you folks out there have any experience with this sort of thing, your help would be much appreciated. :)</p> <hr> <p><strong>Edit:</strong> Basically, the short version of what I want is the simplicity of <code>virtualenv</code>, but without the bundled python interpreter, and a way to activate a specific "virtual environment" programmatically, like <code>zc.buildout</code> does with sys.path manipulation (the <code>sys.path[0:0] = [...]</code> trick).</p> <p>Both <code>virtualenv</code> and <code>zc.buildout</code> contain portions of what I want, but neither produce relocatable builds that I, or a plugin developer can simply zip up and send to another computer.</p> <p>Simply manipulating .pth files, or manipulating <code>sys.path</code> directly in a script, executed from my application gets me half-way there. But it is not enough when compiled modules are necessary, such as the PIL.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload