从PHP调用时pip包导入失败

时间:2019-05-15 14:25:49

标签: php python linux nginx pip

我尝试在共享的Web服务器上运行python脚本。 它可以在SSH中正常运行,例如:

  

./../ python / bin / python cgi-bin / script.py

但是,当我希望它通过PHP运行时,python脚本将运行直到导入pip包。

错误来自导入已安装的pip软件包。

我尝试使用权限鬼混,将所有文件和目录设置为755并使用chmod x 并且我尝试手动并全新安装python 2.7(网络服务器默认运行python 2.6,因此python调用“ ./../python/bin/python”,我无法安装3.5,但出现了很多错误和超时。) 我没有sudo权限。

script.py

print "I will be displayed! yay it works\n"

# import the necessary packages
import numpy as np
import argparse
import cv2
import os

print "I won't be displayed, it does not work!\n"

runpython.php

<?php
$query='./../python/bin/python cgi-bin/script.py 2>&1';
$command=escapeshellcmd($query);
$output=shell_exec($command);
echo $output;

$last_line=system($query, $retval);
echo '</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
?>

我希望两个打印都可以从python脚本中显示,但是它仅显示第一个打印。 导入已安装的pip软件包时出现问题。

Error message (output):
OpenBLAS blas_thread_init: pthread_create failed for thread 15 of 20: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 25 current, 30 max
OpenBLAS blas_thread_init: pthread_create failed for thread 16 of 20: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 25 current, 30 max
OpenBLAS blas_thread_init: pthread_create failed for thread 17 of 20: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 25 current, 30 max
OpenBLAS blas_thread_init: pthread_create failed for thread 18 of 20: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 25 current, 30 max
OpenBLAS blas_thread_init: pthread_create failed for thread 19 of 20: Resource temporarily unavailable
OpenBLAS blas_thread_init: RLIMIT_NPROC 25 current, 30 max


Traceback (most recent call last):
  File "cgi-bin/bw-colorization/bw2color_image.py", line 13, in 
    import numpy as np
  File "/home4/johndooc/python/lib/python2.7/site-packages/numpy/__init__.py", line 142, in 
    from . import core
  File "/home4/johndooc/python/lib/python2.7/site-packages/numpy/core/__init__.py", line 95, in 
    from . import numeric
  File "/home4/johndooc/python/lib/python2.7/site-packages/numpy/core/numeric.py", line 39, in 
    from ._internal import TooHardError, AxisError
  File "/home4/johndooc/python/lib/python2.7/site-packages/numpy/core/_internal.py", line 16, in 
    import ctypes
  File "/home4/johndooc/python/lib/python2.7/ctypes/__init__.py", line 549, in 
    CFUNCTYPE(c_int)(lambda: None)
MemoryError

Last line of the output: MemoryError 
Return value: 1MemoryError

1 个答案:

答案 0 :(得分:0)

用于安装python软件包的用户必须与执行python脚本的用户相同。 这是执行脚本的“网络服务器用户”,我想您是与其他用户一起安装软件包的