gpt4 book ai didi

python - ImportError : numpy. core.multiarray 在使用 mod_wsgi 时导入失败

转载 作者:太空狗 更新时间:2023-10-29 20:28:30 34 4
gpt4 key购买 nike

我在 mod_wsgi 中运行 web.py 脚本时遇到问题。该脚本使用 numpy 和 opencv。

这是我的问题的详细信息。

我有两个 python 版本,但我希望脚本与 python2.7 一起运行。所以从解释器我确保我可以导入 cv 和 numpy

$ python
Python 2.7.3 (default, Oct 8 2013, 15:53:09)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> import numpy
>>> import sys
>>> sys.prefix
'/usr/local'

我从源代码下载了 mod_wsgi,并使用以下命令配置和安装它:

./configure --with-python=/usr/local/bin/python2.7 --with-apxs=/usr/sbin/apxs
LD_RUN_PATH=/usr/local/lib/ make
sudo make install

确保正确配置了 mod_wsgi。

$ ldd /usr/lib64/httpd/modules/mod_wsgi.so 
linux-vdso.so.1 => (0x00007fff36dff000)
libpython2.7.so.1.0 => /usr/local/lib/libpython2.7.so.1.0 (0x00007f9462710000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f94624e8000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f94622e4000)
libutil.so.1 => /lib64/libutil.so.1 (0x00007f94620e1000)
libm.so.6 => /lib64/libm.so.6 (0x00007f9461e5c000)
libc.so.6 => /lib64/libc.so.6 (0x00007f9461ac9000)
/lib64/ld-linux-x86-64.so.2 (0x00007f9462d15000)

此外,我的 httpd.conf

中有以下内容
WSGIPythonHome /usr/local
WSGIPythonPath /usr/local/lib/python2.7/site-packages/

站点包目录包含以下文件:

cv2.so
cv.py
distribute-0.6.35-py2.7.egg
easy-install.pth
numpy-1.7.1-py2.7-linux-x86_64.egg
README
setuptools-0.6c11-py2.7.egg-info
setuptools.pth
web.py-0.37-py2.7.egg

这是脚本:

import web
import json
import cv2
#import numpy as np

urls = (
'.*', 'Sample'
)

class Sample:
def GET(self):
user_data = web.input()
return json.dumps(self.perform(user_data.color, user_data.shade))

def perform (self,color, shade):
return {'color': color, 'shade': shade}

application = web.application(urls, globals()).wsgifunc()

当我从浏览器访问脚本时,我在 error_log

中看到以下错误
[error] ImportError: numpy.core.multiarray failed to import

请注意,这发生在 import cv2 行。如果我也这样评论,就像 import numpy as np 那么我的脚本工作正常。

我已确保我拥有以下文件:

$ sudo find / -name libpython2.7.a
/usr/local/lib/python2.7/config/libpython2.7.a
/usr/local/lib/libpython2.7.a

$ sudo find / -name libpython2.7.so*
/usr/local/lib/libpython2.7.so
/usr/local/lib/libpython2.7.so.1.0
/usr/lib/libpython2.7.so
/usr/lib/libpython2.7.so.1.0

我的 python2.7 配置文件显示:

config.c
config.c.in
install-sh
libpython2.7.a
libpython2.7.so -> ../../libpython2.7.so
libpython2.7.so.1.0 -> ../../libpython2.7.so.1.0
Makefile
makesetup
python.o
Setup
Setup.config
Setup.local

问题

我该怎么做才能解决这个问题?

最佳答案

Windows !你需要下载并安装NumPy 1.6.1和SciPy 0.9.0(你也需要选择支持Python 2.7的文件)

关于python - ImportError : numpy. core.multiarray 在使用 mod_wsgi 时导入失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19307901/

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