PHP exec python not working

hey yall. Im running python on a web server from dreamhost. I use their python installation and use the lastfm module which can be found here: http://code.google.com/p/python-lastfm/

to make it import correctly i do it

import sys
sys.path.append("/home/myusername/build/Python-2.5/Lib/site-packages/")
import lastfm

since the lastfm module is installed there.

When I use putty for ssh on my server, I can just run python test.py and it works fine. But when I run it from php script with

exec("python test.py");

it supposedly does not work, and the script does not run. it works fine when i do

import lastfm

and after that they have other things after, but when I'm actually trying to do something with a module, for example:

import lastfm
api=lastfm.Api(api_key)

. script, python , . - , , PHP . , . , , - , ive 777, . idk, . .

+3
4

python. :

exec ( "/usr/bin/python test.py" )

, :

$, python /USR/ /

+1

, python , stderr. php stderr, ( python):

import sys
sys.stderr = sys.stdout
+1

Windows:

$output = null;
exec('C:\\Python27\\python.exe C:\\sud.py', $output);
echo var_export($output, TRUE);

I've been looking for code all day ^^
That's why - I hope this helps someone.

0
source

For Windows user - Thanks to Karlisup, my PHP file could read python. I use BITNAMI WAMP in Amazon EC2, my python file (leadatos.py) and php file are in the htdocs folder.

My vocation was

<?php
  passthru('C:\\Python27\\python.exe leadatos.py');
 ?>
Run codeHide result

The last line of my Python file was print "message".

Hope these are words!

-1
source

Source: https://habr.com/ru/post/1795008/


All Articles