0

我使用这个脚本在 localhost 的 php 中运行 python 脚本,但它不读取像 numpy 和 cv2 这样的模块。

通过 PHP,当它不读取模块时,我得到了通常的错误:

 import numpy as np ImportError: No module named numpy

我将 python 文件移动到 python 文件夹 C:\Python27 并没有改变任何东西!如果我使用 Python Shell,它就可以工作!

也许这是一个apache问题?

这里,python代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Script Python Example
import time
import sys
import numpy as np


print "Initializing Python Script"

print "The passed arguments are ", sys.argv

print "Writing lines to a file"

ifile = open( "/tmp/testfile", "w+")
for i in range(0,100):
 ifile.write( "One of the lines of the filen" )
 print "Printing line ",i," to /tmp/testfile"

ifile.close()

print "Reading and printing lines of /tmp/testfile"
ifile = open( "/tmp/testfile", "r")
for line in ifile:
 print line
ifile.close()
print "End of Python Script"

PHP代码:

<?php

$param1 = "first";
$param2 = "second";
$param3 = "third";

$command = "python /home/wellington/python_script_example.py";
$command .= " $param1 $param2 $param3 2>&1";

header('Content-Type: text/html; charset=utf-8');
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
echo "<style type='text/css'>
 body{
 background:#000;
 color: #7FFF00;
 font-family:'Lucida Console',sans-serif !important;
 font-size: 12px;
 }
 </style>";

$pid = popen( $command,"r");

echo "<body><pre>";
while( !feof( $pid ) )
{
 echo fread($pid, 256);
 flush();
 ob_flush();
 echo "<script>window.scrollTo(0,99999);</script>";
 usleep(100000);
}
pclose($pid);

echo "</pre><script>window.scrollTo(0,99999);</script>";
echo "<br /><br />Script finalizado<br /><br />";
?>
4

0 回答 0