【问题标题】:pip packages import fails when called from PHP从 PHP 调用 pip 包导入失败
【发布时间】:2019-10-02 17:41:54
【问题描述】:

我尝试在共享网络服务器上运行 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 权限。

脚本.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"

运行python.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

【问题讨论】:

    标签: php python linux nginx pip


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-14
      • 1970-01-01
      • 1970-01-01
      • 2017-08-08
      • 2019-12-07
      相关资源
      最近更新 更多