Ich habe dieses Python 3-Programm, das ich habe Problem ausgeführt. Wenn ich dachte ssh mit python3 4230.py
funktioniert es wie es soll (es druckt Daten), aber wenn ich versuche, es wie python 4230.py
läuft es gibt mir viele Fehler, weil seine PY3-Programm. Also möchte ich einen Weg finden, wie ich dieses PY-Skript, das ich habe, machen könnte, um die Antworten auszudrucken. Um alles Python druckt auf der Website Echo, ich bin mit diesem WP Plugin:Wie python3 auf dem Webserver laufen?
<?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;
}
Es sollte keine Syntaxfehler in diesem Code, habe ich kein Problem mit ihm hatte und python3 wenn ich arbeitete WAMP . Aber ich dachte, dass dieser Code das Python-Programm aktivieren sollte, vielleicht ist es also möglich, eine Anfrage zu senden, damit Python mit python3
läuft?
auch als which python3
durch ssh druckt /home/meteo/.local/bin/python3
, ich habe versucht, diese Linie an die Spitze der Mine Python-Skript als „shebang“ hinzufügen wie diese #!/home/meteo/.local/bin/python3
aber es hat nicht geholfen meine PY Skript ausgeführt und python3
zum Ausdrucken die Daten.
Also was soll ich tun, damit dieses Python-Skript als python3 ausgeführt wird und die Antwort ausgedruckt wird?
EDIT: Das ist der Fehler, den ich bekomme, wenn ich Python-Skript laufen mit 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: Fest dieses Problem mit neuen 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;
}
Danke fürs Lesen.
Haben Sie versucht, '$ application_system = "Python" zu ändern;' auf '$ application_system = "python3";'? –
@MaximilianPeters Ja, tat ich, hat nicht geholfen. – MakeMeWise
Sind Sie sicher, dass es sich um ein Python3/Python2-Problem handelt und nicht um ein Problem, wie das Skript aufgerufen wird? Unterschiedliche Benutzerrechte? Befehlszeilenargumente usw.? –