Answers.Body: <p>I think you're going to have a bad time if you attempt to do this. Probably a better way would be to use <a href="https://github.com/PHPOffice/PHPPresentation" rel="nofollow noreferrer">PHPPresentation</a> to read in the <code>.pptx</code> files.</p>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-27T05:40:54.800Z
Answers.Text: 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.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-27T22:07:16.010Z
Answers.Text: Boo, the answer I was expecting but not the one I was hoping for. Thanks for the info and the library!
Answers.UserDisplayName: ZombieShellback
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-27T02:23:31.357Z
Answers.LastActivityDate: 2018-07-27T02:23:31.357Z
Answers.UserDisplayName: andrew.welch
Body: <p>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 <a href="https://docs.python.org/2/tutorial/datastructures.html#dictionaries" rel="nofollow noreferrer">Dictionary</a> of slides. I've also tried returning different things from the Python script, even as simple as a Hello World string. </p>
  
  <p>For simplicity's sake, I just have this code in my <code>onAfterInstall()</code> method:</p>
  
  <pre><code>$output = shell_exec("import_ppt.py 'original.pptx' ");
      var_dump($output);
  var_dump($output);
  </code></pre>
  
  <p>For the filepath, I've also tried <code>".realpath(dirname(__FILE__))."/</code> as well, to no avail. I always get a <code>NULL</code> return and a PHP warning about not being able to modify headers. </p>
  
  <p>Then, in my Python file, I have:</p>
  
  <pre><code>if __name__ == '__main__':
  import sys
  buildSlideshow(sys.argv[1])
  </code></pre>
  
  <p>buildSlideshow takes one argument, which is the filepath of the powerpoint file, and eventually returns the dictionary of slides and slide content.</p>
  
  <p>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:</p>
  
  <p>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.</p>
  
Tags: <plugin-development><php>
Title: Is it possible to create a plugin using Python in Craft 2?
ThreadText: # Is it possible to create a plugin using Python in Craft 2?
  
  (Asked by: username_0 on 2018-07-27)
  
  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](https://docs.python.org/2/tutorial/datastructures.html#dictionaries) 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' ");
      var_dump($output);
  var_dump($output);
  
  ```
  
  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(sys.argv[1])
  
  ```
  
  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.
  
  **Tags:** plugin-development, php
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-07-27. Score: 2 | Accepted answer
  
  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](https://github.com/PHPOffice/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.
  
  > **Comments:**
  > **username_2**: 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.  
  > **username_0**: Boo, the answer I was expecting but not the one I was hoping for. Thanks for the info and the library!  
  
  ---
  
  