ImportError: numpy.core.multiarray import fehlgeschlagen, während mit mod_wsgi
Ich habe Probleme beim ausführen eines web.py
script in mod_wsgi
. Das Skript verwendet numpy und opencv.
Hier sind die details von meinem problem.
Habe ich zwei python-Versionen auf der box, aber ich möchte das Skript ausführen, mit python2.7. So aus dem interpreter habe ich dafür gesorgt, dass ich importieren kann cv und 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'
Ich heruntergeladen mod_wsgi von der Quelle, konfiguriert und installiert es mit dem Befehl unten:
./configure --with-python=/usr/local/bin/python2.7 --with-apxs=/usr/sbin/apxs
LD_RUN_PATH=/usr/local/lib/ make
sudo make install
Sicherzustellen, dass mod_wsgi richtig konfiguriert ist.
$ 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)
Außerdem habe ich das folgende in meine httpd.conf
WSGIPythonHome /usr/local
WSGIPythonPath /usr/local/lib/python2.7/site-packages/
den site-packages-Verzeichnis enthält die folgenden Dateien:
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
Hier ist das Skript:
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()
Wenn ich das script aus dem browser sehe ich die Fehler unten in error_log
[error] ImportError: numpy.core.multiarray failed to import
beachten Sie, dass in diesem Fall auf import cv2
Linie. Wenn ich den Kommentar, dass auch, genau wie import numpy as np
dann mein Skript funktioniert.
Habe ich sichergestellt, dass ich die folgenden Dateien:
$ 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
Mein python2.7 config-Datei zeigt:
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
Frage
Was kann ich tun, um dieses Problem zu beheben?
- hast du eine Lösung für dieses prob?
- Hat der Fehler passiert, wenn du nur import numpy in Ihrem wsgi-Skript? Wenn es nicht passiert, versuchen Sie, import numpy vor dem import cv2, dass das helfen könnte.
Du musst angemeldet sein, um einen Kommentar abzugeben.
für Windows ! Sie müssen downloaden und installieren Sie NumPy 1.6.1 und SciPy 0.9.0 (Sie müssen wählen Sie die Dateien, die Unterstützung für Python 2.7 zu)
mod_wsgi
?Installieren
numpy
mitpip install numpy
. Ich erstelltevirtualenv
und installiert alle Pakete und es gibt keine Fehler. Möglicherweise problem mit alten NumPy, ich habe die version 1.8.1. Meine Variablen innerhalb von Apache virtual host:Ich denke, dass Sie nicht brauchen
/usr/local/lib/python2.7/dist-packages/
Weg, weil, das ist für Debian-basierte Linuces nur.Wenn Sie vermuten, dass problem ist eigentlich mit OpenCV, die mit dem Befehl
locate cv2.so
erhalten Sie den Pfad, wo OpenCV gemeinsamen Modul befindet und das Verzeichnis muss inWSGIPythonPath
.