2

On my raspberry pi I created a virtual environment with the virtualenv package. Using pip3 I installed the following python packages for python 3.5:

imutils==0.5.2
numpy==1.16.3
opencv-contrib-python==3.4.2.17
picamera==1.13
scikit-learn==0.20.3
scipy==1.2.1
sklearn=0.0

Importing these packages in my python script results in an importerror due to the sklearn package

I recreated a new virtual environment from scratch and installed every package again with an older version of numpy as I read that numpy sometimes could be the problem, this was not succesful. Additionally, I created a virtualenv with python 3.6 and attempted to install the packages there but I ran into different errors such as failing to build the pip wheel.

Input:

(testenv) pi@raspberrypi:~/yetiborgv2/Project/opencv-face-recognition $ python3.5 test_face_script_python3.py

Output:

Libraries loaded
[INFO] loading face detector...
[INFO] loading face recognizer...
Traceback (most recent call last):
  File "test_face_script_python3.py", line 40, in <module>
    recognizer = pickle.loads(open(main_path + 'output/recognizer.pickle', "rb").read())
  File "/home/pi/yetiborgv2/Project/opencv-face-recognition/testenv/lib/python3.5/site-packages/sklearn/svm/__init__.py", line 13, in <module>
    from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC, \
  File "/home/pi/yetiborgv2/Project/opencv-face-recognition/testenv/lib/python3.5/site-packages/sklearn/svm/classes.py", line 4, in <module>
    from .base import _fit_liblinear, BaseSVC, BaseLibSVM
  File "/home/pi/yetiborgv2/Project/opencv-face-recognition/testenv/lib/python3.5/site-packages/sklearn/svm/base.py", line 8, in <module>
    from . import libsvm, liblinear
ImportError: /home/pi/yetiborgv2/Project/opencv-face-recognition/testenv/lib/python3.5/site-packages/sklearn/svm/liblinear.cpython-35m-arm-linux-gnueabihf.so: undefined symbol: cblas_dnrm2

I got this from ldd -r the .so file

pi@raspberrypi:~/yetiborgv2/Project/opencv-face-recognition/testenv/lib/python3.5/site-packages/sklearn/svm $ ldd -r liblinear.cpython-35m-arm-linux-gnueabihf.so

Output:

linear.cpython-35m-arm-linux-gnueabihf.so
        /usr/lib/arm-linux-gnueabihf/libarmmem.so (0xb6f6f000)
        libcblas.so.3 => /usr/lib/arm-linux-gnueabihf/libcblas.so.3 (0xb6efc000)
        libstdc++.so.6 => /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 (0xb6db4000)
        libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xb6d35000)
        libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0xb6d08000)
        libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xb6cdf000)
        libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6ba0000)
        /lib/ld-linux-armhf.so.3 (0xb6fac000)
        libf2c.so.2 => /usr/lib/arm-linux-gnueabihf/libf2c.so.2 (0xb6b77000)
undefined symbol: PyExc_ValueError      (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyFrame_Type  (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: _Py_TrueStruct        (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyTuple_Type  (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyList_Type   (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyCapsule_Type        (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: _Py_NoneStruct        (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyExc_AttributeError  (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyFunction_Type       (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyCFunction_Type      (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyExc_OverflowError   (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyExc_NameError       (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyExc_Exception       (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyExc_DeprecationWarning      (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyExc_RuntimeError    (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyBaseObject_Type     (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyExc_TypeError       (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: _Py_FalseStruct       (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyLong_Type   (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyFloat_Type  (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyExc_SystemError     (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyExc_ImportError     (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: _Py_CheckRecursionLimit       (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyObject_Hash (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyObject_GetBuffer    (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyLong_AsLong (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyLong_FromSsize_t    (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyMem_Realloc (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: cblas_dnrm2   (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyObject_GetAttr      (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyDict_GetItemString  (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyImport_AddModule    (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyObject_Call (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyUnicode_AsUnicode   (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: cblas_ddot    (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyTuple_Pack  (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyErr_NormalizeException      (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyObject_GetAttrString        (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: cblas_daxpy   (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyErr_Restore (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyModule_GetDict      (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyTraceBack_Here      (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyCode_New    (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyDict_SetItem        (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyErr_WarnEx  (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyUnicode_InternFromString    (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyTuple_New   (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyObject_SetAttr      (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyEval_RestoreThread  (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyException_SetTraceback      (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyDict_SetItemString  (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyUnicode_FromFormat  (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyBytes_FromStringAndSize     (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyImport_GetModuleDict        (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyDict_Next   (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyErr_SetObject       (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyBuffer_Release      (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyBytes_FromString    (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyErr_Format  (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyFloat_AsDouble      (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyMem_Malloc  (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyErr_ExceptionMatches        (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyCFunction_NewEx     (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyList_New    (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyImport_ImportModule (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: _PyObject_GetDictPtr  (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyUnicode_FromString  (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: Py_GetVersion (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyErr_Clear   (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyModule_NewObject    (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyOS_snprintf (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyDict_New    (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyErr_SetString       (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyThreadState_Get     (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: _PyDict_GetItem_KnownHash     (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: cblas_dscal   (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyObject_SetAttrString        (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyCapsule_GetPointer  (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyObject_Not  (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyUnicode_Decode      (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyObject_GetItem      (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: _Py_CheckRecursiveCall        (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyEval_SaveThread     (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyLong_FromLong       (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyObject_IsTrue       (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyErr_WarnFormat      (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyLong_AsUnsignedLong (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyErr_Occurred        (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyErr_Fetch   (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyImport_ImportModuleLevelObject      (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyFrame_New   (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyDict_Size   (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyEval_EvalFrameEx    (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyUnicode_Compare     (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyModuleDef_Init      (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyErr_GivenExceptionMatches   (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyEval_EvalCodeEx     (./liblinear.cpython-35m-arm-linux-gnueabihf.so)
undefined symbol: PyUnicode_FromStringAndSize   (./liblinear.cpython-35m-arm-linux-gnueabihf.so)

EDIT (PARTIAL) SOLUTION!!!!:

After following these steps of the link below I managed to fix the scipy error, I uninstalled numpy, scipy and scikit-learn. Using apt-get install I installed the following things:

apt-get install libopenblas-base
apt-get install libopenblas-dev
apt-get install python-dev
apt-get install gcc
apt-get install gfortran

I then installed the lowest version of numpy needed with pip, and then installed scipy and scikit-learn. How to install latest Scipy version on Raspberry Pi

But then I run into another error that says the following without further detail:

Illegal instruction

How can I fix this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.