みなさま、おはようございます。
今朝は、pythonの使用で少しハマったところを
記録しておきたいと思います。
(暫定対処な感じですので、ちょっと違う。。。
などございましたら、ご連絡ください)
内容としては、CentOS7 + Python2.7 + Apache2 にて、
#!/bin/python
import numpy as np
・
・
・
というコードで、いきなり、
Traceback (most recent call last):
File “/var/www/cgi-bin/test.py”, line 5, in
import numpy as np
File “/usr/local/lib/python2.7/site-packages/numpy/__init__.py”, line 180, in
from . import add_newdocs
File “/usr/local/lib/python2.7/site-packages/numpy/add_newdocs.py”, line 13, in
from numpy.lib import add_newdoc
File “/usr/local/lib/python2.7/site-packages/numpy/lib/__init__.py”, line 8, in
from .type_check import *
File “/usr/local/lib/python2.7/site-packages/numpy/lib/type_check.py”, line 11, in
import numpy.core.numeric as _nx
File “/usr/local/lib/python2.7/site-packages/numpy/core/__init__.py”, line 22, in
from . import _internal # for freeze programs
File “/usr/local/lib/python2.7/site-packages/numpy/core/_internal.py”, line 14, in
import ctypes
File “/usr/local/lib/python2.7/ctypes/__init__.py”, line 555, in
_reset_cache()
File “/usr/local/lib/python2.7/ctypes/__init__.py”, line 279, in _reset_cache
CFUNCTYPE(c_int)(lambda: None)
MemoryError
というようなエラーで出る場合、
lib/python2.7/ctypes/__init__.py の、下記の部分、
# XXX for whatever reasons, creating the first instance of a callback
# function is needed for the unittests on Win64 to succeed. This MAY
# be a compiler bug, since the problem occurs only when _ctypes is
# compiled with the MS SDK compiler. Or an uninitialized variable?
CFUNCTYPE(c_int)(lambda: None)
の「CFUNCTYPE(c_int)(lambda: None)」をコメントアウトします。
※元ネタ
http://stackoverflow.com/questions/3762566/occasional-ctypes-error-importing-numpy-from-mod-wsgi-django-app/6769624#6769624