I have this python 3 program that I have problem running. When I run thought ssh using python3 4230.py
it works like it should(it prints out data), but when I try to run it like python 4230.py
it gives me lots of errors because its PY3 program. So I want to find a way on how could I make that this PY script I have, would print out the answers. To echo everything python prints on website, I am using this WP plugin:
<?php # -*- coding: utf-8 -*-
/* Plugin Name: 4230 */
header('Content-Type: text/html; charset=cp1252');
add_shortcode( '4230', 'execute_python_with_argv' );
function execute_python_with_argv(){
ob_start();
$description = array (
0 => array("pipe", "r"), // stdin
1 => array("pipe", "w"), // stdout
);
$application_system = "python ";
$application_path .= plugin_dir_path( __FILE__ );
$application_name .= "4230.py";
$separator = " ";
$application = $application_system.$application_path.$application_name.$separator;
$pipes = array();
$proc = proc_open ( $application , $description , $pipes );
if (is_resource ( $proc ))
{
$var= stream_get_contents ($pipes [1] ); //Reading stdout buffer
}
echo "<pre>".$var."</pre>";
$output = ob_get_clean();
return $output;
}
There should not be any syntax errors in this code, I didn't had any problem with it and python3 when I was working on WAMP. But I though that this code should activate python program, so maybe it is possible to make it send request for python to run with python3
?
Also as which python3
through ssh prints out /home/meteo/.local/bin/python3
, I have tried to add this line to the top of mine python script as a "shebang" like this #!/home/meteo/.local/bin/python3
but it didn't help running my PY script and python3
to print out the data.
So what should I do to make this python script to run as python3 and print out the answer?
EDIT: This is the error I get when I run python script with python 4230.py
:
Traceback (most recent call last):
File "4230.py", line 4, in <module>
from bs4 import BeautifulSoup
File "/home/meteo/public_html/wp-content/plugins/bs4/__init__.py", line 30, in <module>
from .builder import builder_registry, ParserRejectedMarkup
File "/home/meteo/public_html/wp-content/plugins/bs4/builder/__init__.py", line 4, in <module>
from bs4.element import (
File "/home/meteo/public_html/wp-content/plugins/bs4/element.py", line 8, in <module>
from bs4.dammit import EntitySubstitution
File "/home/meteo/public_html/wp-content/plugins/bs4/dammit.py", line 13, in <module>
from html.entities import codepoint2name
ImportError: No module named html.entities
EDITv2: Fixed this problem with new WP plugin:
<?php # -*- coding: utf-8 -*-
/* Plugin Name: viassh */
header('Content-Type: text/html; charset=ANSI_X3.4-1968');
add_shortcode('viassh', 'HelloWorldShortcode');
function HelloWorldShortcode() {
ob_start();
$old_path = getcwd();
chdir('/home/meteo/public_html/wp-content/plugins/');
$output = shell_exec('./4230.py');
chdir($old_path);
echo $output;
$output = ob_get_clean();
return $output;
}
Thanks for reading.