我在mod_wsgi
中運行web.py
腳本時遇到問題。腳本使用numpy和opencv。ImportError:numpy.core.multiarray在使用mod_wsgi時無法導入
下面是我的問題的詳細信息。
我已經有兩個python版本的盒子,但我想腳本與python2.7運行。所以從解釋,我保證,我可以導入簡歷和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和配置,並與下面的命令安裝它:
確保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
問題
我能做些什麼來解決這個問題?
您是否找到了解決此問題的解決方案? – samkhan13
如果您僅在wsgi腳本中導入numpy,是否會發生錯誤?如果它沒有發生,請在導入cv2之前嘗試輸入numpy,這可能有所幫助。 – Aldarund