gpt4 book ai didi

php - 从 PHP 调用时 pip 包导入失败

转载 作者:太空狗 更新时间:2023-10-29 12:39:01 28 4
gpt4 key购买 nike

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

最佳答案

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

关于php - 从 PHP 调用时 pip 包导入失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56151707/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com