Python with wordpress plugin

I am trying to do some experiments with python and wordpress plugins. I would like to have shortcode [python] with some functionalities. I was trying this metod - Method i tried, but when I do everything by that i got error message - sh: 1: /www/doc/mywebsitename/www/wp-content/plugins/PythonEmbed/pythonScript.py: not found

My PHP code:

?php # -*- coding: utf-8 -*-
/**
 * Plugin Name: PythonWeb
 * Description: Python integration on web
 * Version: 0.0.1
 * Author: mywebsitename
 * Author URI: mywebsitename
 */

add_shortcode( 'python', 'embed_python' );

function embed_python( $attributes )
{
    echo PHP start!br;
    $data = shortcode_atts(
        [
            'file' = 'pythonScript.py'
        ],
        $attributes
    );

    $handle = popen( __DIR__ . '/' . $data['file'] . ' 21', 'r' );
    $read = '';
    
    while ( ! feof( $handle ) )
    {
        $read .= fread( $handle, 2096 );
    }

    pclose( $handle );
    
    return $read;
}

Python test code:

#!/usr/bin/python

print Python is running !!!

Can someone help me to run python code in WordPress plugin so i could test some things? Thanks for any help.

Topic testing plugin-development errors plugins Wordpress python

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.