plugins - Trouble implementing python on WordPress

I followed all the directions in this post and I still cannot get a result to display. I know PHP is doing something, be

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"].

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"].

Share Improve this question edited Jun 1, 2020 at 16:01 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Sep 2, 2015 at 2:32 arabiccodearabiccode 113 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742383849a4433653.html

相关推荐

  • plugins - Trouble implementing python on WordPress

    I followed all the directions in this post and I still cannot get a result to display. I know PHP is doing something, be

    2天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信