0

I followed all the directions in this post and I still cannot get a result to display. I know PHP is doing something, because there is no text displayed whatsoever. The result has a header and no body content. When the plugin is disabled, it displays the shortcode as plain text.

<?php # -*- coding: utf-8 -*-
/* Plugin Name: Python embedded */

add_shortcode( 'python', 'embed_python' );

function embed_python( $attributes )
{
    $data = shortcode_atts(
        array(
            'file' => 'hello.py'
        ),
        $attributes
    );
    $handle = popen( __DIR__ . '/' . $data['file'], 'r');
    $read   = fread($handle, 2096);
    pclose($handle);

    return $read;
}

I uploaded hello.py and Python.php to the plugins folder and made sure the plugin was properly activated.

In my post editor I have: [python file="hello.py"].

  • do you have debugging enabled? – Milo Sep 2 '15 at 3:25
  • 1
    What if you rename hello.py to filename.py? Or remove the file="filename.py"? By including filename.py in your shortcode you are telling the embed_python function that $data[file] is filename.py – czerspalace Sep 2 '15 at 4:53
  • Sorry, that was a poor example. I literally have: [python file="hello.py"] – arabiccode Sep 2 '15 at 18:34
  • Ok, I found the solution. First of all, you have to $handle = popen('env python '. __DIR__ . '/' . $data['file'], 'r'); More importantly, I had to install Python 2.7.2 on Bluehost. my.bluehost.com/cgi/help/python-install – arabiccode Sep 2 '15 at 19:39
  • Please post your solution as an answer to the original question. – fuxia Sep 4 '15 at 15:56
0

Ok, I found the solution. First of all, you have to

$handle = popen('env python '. DIR . '/' . $data['file'], 'r');

More importantly, I had to install Python 2.7.2 on Bluehost

  • You can accept your answer so the question is no longer considered unanswered; click the check mark under the vote arrows on the left. – Gabriel Jun 1 '16 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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