I've been searching and trying things for a few days now, but I feel like I'm spinning my wheels. I've got a Python script that reads in a .pptx file, and returns a Dictionary of slides. I've also tried returning different things from the Python script, even as simple as a Hello World string.

For simplicity's sake, I just have this code in my onAfterInstall() method:

$output = shell_exec("import_ppt.py 'original.pptx' ");

For the filepath, I've also tried ".realpath(dirname(__FILE__))."/ as well, to no avail. I always get a NULL return and a PHP warning about not being able to modify headers.

Then, in my Python file, I have:

if __name__ == '__main__':
import sys

buildSlideshow takes one argument, which is the filepath of the powerpoint file, and eventually returns the dictionary of slides and slide content.

I know that the error isn't in my Python code, as if I run it in shell I don't have any problems with it and get the result I want. So, my overall question is this:

Is what I'm trying to do a pipe dream, or am I just missing something major? I can't find any docs about CraftxPython, simply searching the word "Python" on this very site brought up no results, and when I tried looking up how to incorporate Python into a Craft 2 plugin, all I got was information on how to create a plugin for Python.

1 Answer 1


I think you're going to have a bad time if you attempt to do this. Probably a better way would be to use PHPPresentation to read in the .pptx files.

Integration is certainly possible between server-side languages, but you're going to have to jump through a good deal of hoops that you could more easily just avoid by writing your plugin in PHP.

  • I'll add that one of the several hoops you'd have to jump through is the fact that PHP doesn't have any idea what a Python Dictionary data structure is. So in your current strategy, you'd have to capture an output buffer of data, then parse/eval it to turn it into a PHP associative array. You'd save yourself a lot of headaches just by writing that logic in PHP to begin with.
    – Brad Bell
    Commented Jul 27, 2018 at 5:40
  • Boo, the answer I was expecting but not the one I was hoping for. Thanks for the info and the library! Commented Jul 27, 2018 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.