scikit-learn - 如何修复 ImportError: Undefined Symbol from the sklearn package in python 3.5 on raspberry pi
问题描述
在我的树莓派上,我使用 virtualenv 包创建了一个虚拟环境。使用 pip3 我为 python 3.5 安装了以下 python 包:
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
由于 sklearn 包,在我的 python 脚本中导入这些包会导致导入错误
我从头开始重新创建了一个新的虚拟环境,并使用旧版本的 numpy 再次安装了每个包,因为我读到 numpy 有时可能是问题所在,这并不成功。此外,我使用 python 3.6 创建了一个 virtualenv 并尝试在那里安装软件包,但我遇到了不同的错误,例如未能构建 pip 轮。
输入:
(testenv) pi@raspberrypi:~/yetiborgv2/Project/opencv-face-recognition $ python3.5 test_face_script_python3.py
输出:
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
我从 ldd -r .so 文件中得到了这个
pi@raspberrypi:~/yetiborgv2/Project/opencv-face-recognition/testenv/lib/python3.5/site-packages/sklearn/svm $ ldd -r liblinear.cpython-35m-arm-linux-gnueabihf.so
输出:
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)
编辑(部分)解决方案!!!!:
按照下面链接的这些步骤后,我设法修复了 scipy 错误,我卸载了 numpy、scipy 和 scikit-learn。使用 apt-get install 我安装了以下东西:
apt-get install libopenblas-base
apt-get install libopenblas-dev
apt-get install python-dev
apt-get install gcc
apt-get install gfortran
然后我安装了 pip 所需的最低版本的 numpy,然后安装了 scipy 和 scikit-learn。 https://raspberrypi.stackexchange.com/questions/8308/how-to-install-latest-scipy-version-on-raspberry-pi
但后来我遇到了另一个错误,上面没有进一步的细节:
Illegal instruction
我怎样才能解决这个问题?
解决方案
推荐阅读
- c++ - 为什么这段代码不直接使用 C++ 幂函数?有人可以帮助我使用此代码中的电源功能吗?
- python - 如何将 csv 转换并格式化为包含标题名称的列表列表
- kotlin - 为什么 Kotlin 的 Number-class 缺少运算符?
- r - 如何将原始向量从 sqlQuery 转换为数据框中的单个字符串?
- mysql - 一大列还是许多小行?
- c# - 如何使用 Microsoft Graph API 从包含嵌套组的组中仅获取用户?
- julia - (Julia 1.x) 获取#undef 变量的类型
- django - Django prefetch_related 似乎无法按预期工作
- vue.js - 如何从 Vuex 操作中的 axios 函数返回错误消息以调度 catch(error)?
- laravel - subCategories 函数已定义,但我得到的只是调用未定义的方法 Illuminate\Database\Eloquent\Builder::subCategories()"