Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installing opencv-python #1992

Closed
AvielNiego opened this issue Jan 2, 2018 · 98 comments · Fixed by #9369
Closed

Installing opencv-python #1992

AvielNiego opened this issue Jan 2, 2018 · 98 comments · Fixed by #9369
Labels
python Issue is about Python related stuff, including pip

Comments

@AvielNiego
Copy link

Hey,

Is there a way to install opencv-python?
The standard
pip3 install opencv-python
returns

Could not find version that satisfies the requirement opencv-python (from versions: )
No matching distribution found for opencv-python
@Grimler91
Copy link
Member

Grimler91 commented Jan 2, 2018

I'm working on adding a short build tutorial to https://wiki.termux.com/wiki/Instructions_for_installing_python_packages.
GUI will need to be disabled of course.

It isn't entirely trivial though, some patching is needed, so it might be worth to package it properly in the long run.

@Grimler91
Copy link
Member

There are old instructions in #512 but they seem to be outdated due to the problem described in #1149.

@its-pointless
Copy link
Contributor

I have cross compiled it in the past but cross compiling and getting python module i have not done.

@Grimler91
Copy link
Member

@its-pointless I guess that could be problematic. It seems to use python during the build, and also requires numpy, which is in your repo and not the main repo. The package would probably have to reside in your repository then.

I'll continue looking at instructions for compilation on device in any case.

@AvielNiego
Copy link
Author

Thanks a lot!

@Grimler91
Copy link
Member

@AvielNiego Please try the instructions at https://wiki.termux.com/wiki/Instructions_for_installing_python_packages#opencv.
Compilation takes quite a lot of time.

@AvielNiego
Copy link
Author

AvielNiego commented Jan 4, 2018

Thanks!
I did encounter the problems from #1149
After the make command I get this error:

fatal error: too many errors emitted, stopping now [-ferror-limit=]
40 warnings and 20 errors generated

Most of the errors are:
error: no matching function for call 'max'
(around 9 times)
the others are:

error: no member named 'fpclassify' in global namespace
error: no member anmed 'isfinite' in global namespace; did you mane 'finite'?
error: no member anmed 'isnormal' in global namespace
error: no member anmed 'isgreater' in global namespace; did you mane '::std::greater'?
error: no member anmed 'isgreaterequal' in global namespace; did you mane '::std::greater_equal'?
error: no member named 'isless' in global namespace
error: no member named 'islessequal' in global namespace
error: no member named 'islessgreater' in global namespace
error: no member named 'isunordered' in global namespace
error: no member named 'isunordered' in global namespace

@Grimler91
Copy link
Member

I believe this is fixed by commit 4130315, try updating all packages and see if it is resolved (you might have to remove the opencv/build folder and start over).

@AvielNiego
Copy link
Author

AvielNiego commented Jan 4, 2018

It worked!
Now when I try to import cv2 in python like that:
import cv2
I get some warnings and this error

dlopen failed: cannot locate symbol "PyFloat_Type" referenced by "/data/data/com.termux/usr/lib/python3.6/site-packages/cv2.cpython-36m.so

whatsapp image 2018-01-04 at 14 34 33

@Grimler91
Copy link
Member

The warnings can be removed with by running termux-elf-cleaner on the libs, see the readme for more information.

"Cannot locate symbol"-issues are most often solved by first making sure the library providing the symbol is installed, and then running the installation with LDFLAGS set to point to the library containing the symbol that wasn't found.

From https://bugs.kde.org/show_bug.cgi?id=335965 it looks like the symbol should be in libboost_python.so.
However, our boost is built without python support so it won't work.

It should be possible to add python supported to boost, it is discussed in the pull request and it is also needed by at least one other package, dlib.

When python support for boost exists, you might need to rebuild opencv with -lboost_python added to LDFLAGS (i.e. LDFLAGS=" -llog -lboost_python" cmake ...).

@its-pointless
Copy link
Contributor

k iv made a pull request #2004 to add libbost.python if you wait a few momemnts i will get binaries available.

@Grimler91
Copy link
Member

@its-pointless I tried building opencv again, with LDFLAGS=" -llog -lboost_python-3" cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$PREFIX -DBUILD_opencv_python3=on -DBUILD_opencv_python2=off -DWITH_QT=OFF -DWITH_GTK=OFF ..

But ran into quite a lot of undefined references

/data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_FromFormat'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_SetItem'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyList_New'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_AsWideChar'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceFloorDivide'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_Size'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyModule_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyArg_ParseTupleAndKeywords'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_Items'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyProperty_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyMethod_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyList_Insert'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyExc_ReferenceError'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyFloat_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyTuple_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_Lshift'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_ClearWeakRefs'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_CallMethod'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyMem_Free'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyCFunction_NewEx'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceAdd'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyLong_AsUnsignedLongLong'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_Add'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_GetAttrString'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_AsUTF8String'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_SetAttrString'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_WarnEx'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_NoMemory'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_SetObject'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyIter_Next'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_Multiply'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `_Py_NotImplementedStruct'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_RichCompare'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyRun_FileExFlags'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyExc_RuntimeError'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_SetString'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_IsInstance'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_DelItem'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyMethod_New'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_GetItem'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyExc_ValueError'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyExc_TypeError'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyStaticMethod_New'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyTuple_GetItem'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyComplex_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_ExceptionMatches'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceAnd'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyType_Ready'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyLong_FromLong'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyComplex_ImagAsDouble'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyLong_AsSsize_t'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyBytes_Size'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_GetItem'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_NewException'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_Clear'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyBool_FromLong'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyList_Append'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_Clear'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_Update'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_Or'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_And'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_CallFunction'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyTuple_New'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyExc_OverflowError'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_Remainder'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyType_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_SetAttr'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_Occurred'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyModule_Create2'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyLong_AsLong'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyImport_ImportModule'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyEval_GetGlobals'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceOr'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceXor'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `_Py_fopen'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyRun_StringFlags'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_GetItemString'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyList_Reverse'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyList_Sort'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_Size'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `_Py_NoneStruct'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_IsTrue'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `_PyType_Lookup'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyEval_CallFunction'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyType_GenericAlloc'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceRshift'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyStaticMethod_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyWeakref_NewRef'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_Rshift'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceRemainder'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_New'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyExc_IndexError'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyBool_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyCallable_Check'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyLong_AsUnsignedLong'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyBaseObject_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyLong_FromUnsignedLong'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_AsUTF8'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyLong_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_Keys'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `_PyObject_New'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_FromString'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_InternFromString'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyExc_AttributeError'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_Copy'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyBytes_AsString'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyExc_StopIteration'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_Call'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyLong_AsLongLong'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyType_IsSubtype'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyTuple_Size'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceLshift'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyErr_Format'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PySlice_New'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_FromStringAndSize'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceMultiply'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyObject_GetAttr'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyCFunction_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyUnicode_FromEncodedObject'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyComplex_RealAsDouble'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyMem_Malloc'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_Subtract'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_Xor'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_InPlaceSubtract'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyList_Type'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyNumber_FloorDivide'
    /data/data/com.termux/files/usr/bin/../lib/libboost_python-3.so: undefined reference to `PyDict_Values'

Could/should this be dealt with when compiling boost or should/do I need to link against the corresponding libs on device?

@its-pointless
Copy link
Contributor

I think adding -lpython3 to ldflags should work. But its probably best make sure boost-python links before hand.

@Grimler91
Copy link
Member

@its-pointless neither -lpython3 or -lpython3.6m works (identical output) so I'm guessing we need to link when building boost. I can try it tomorrow.

@its-pointless
Copy link
Contributor

i made a big update for boost. fornwall accepted pull request of mine which actually breaks stuff .... oops sorry my fault.
i will get a lib up that should work shortly.
Which arch you using to test grimler?

@Grimler91
Copy link
Member

@its-pointless thanks for your work. Aarch64 would be preferred.

@its-pointless
Copy link
Contributor

Already in official repo

@Grimler91
Copy link
Member

@its-pointless Which PR are you talking about?
Don't you think something along the lines of your changes in #2006 is needed?

@its-pointless
Copy link
Contributor

I think i upped to my repo with properly linked libs. try that

@Grimler91
Copy link
Member

@its-pointless Yepp, your latest version there fixes it, no more errors on import cv2.

Are you planning to open a new pull request for the termux repo?

@its-pointless
Copy link
Contributor

I suppose i should ... again

@isman7
Copy link

isman7 commented Mar 30, 2018

Hi! I've been trying to reproduce the OpenCV compiling in my Termux (Android 8, aarch64) and I'm repeteadly failing at this point:

[ 29%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o /data/data/com.termux/files/home/opencv-3.0.0/modules/core/src/system.cpp:645:29: error: use of undeclared identifier 'ANDROID_LOG_ERROR' __android_log_print(ANDROID_L... ^ 1 error generated.
make[2]: * [modules/core/CMakeFiles/opencv_core.dir/build.make:1026: modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o] Error 1 make[1]: * [CMakeFiles/Makefile2:1585: modules/core/CMakeFiles/opencv_core.dir/all] Error 2

Using as Cmake flags LDFLAGS=" -llog -lpython3". I've readed a lot and I supose it's related with the uncorrect linking something, but I'm not a CMake expert. I could use some help.

Thank you,

Isma

@Grimler91
Copy link
Member

@isman7 see the (possibly outdated) instructions at https://wiki.termux.com/wiki/Instructions_for_installing_python_packages#opencv.
How did you set LDFLAGS?

@isman7
Copy link

isman7 commented Mar 31, 2018

Yes yes, I followed the insturctions. I used them with -llog and with -lpython3 and the same error raised. In fact, for versions 2.4.13.6 and 3.0.0 I found this error, for newest version I found another error related with 3rd party libs, so I decided to go down.

Searching I found similar issues here: https://stackoverflow.com/questions/4455941/undefined-reference-to-android-log-print

However this is talking about compiling some Android SDK stuff, and I don't know how to adapt the line of Android.mk to Makefile.

@Grimler91
Copy link
Member

Grimler91 commented Mar 31, 2018

I don't think -lpython is necessary, can't remember that I used it at least.

Install libboost-python and try this exact command:

LDFLAGS=" -llog -lboost_python" cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$PREFIX -DBUILD_opencv_python3=on -DBUILD_opencv_python2=off -DWITH_QT=OFF -DWITH_GTK=OFF ..

From a subdirectory ("build") in the opencv folder, note that everything is on one line.

@isman7
Copy link

isman7 commented Mar 31, 2018

Sorry, pre-pended!

The only thing i haven't tried it's libboost-python. I'll try again with lboost, and I'll report about in an hour.

Thanks for the support!

@tomty89
Copy link
Contributor

tomty89 commented Mar 31, 2018

It's normal for you to get that error because there was a bug in those two versions:

https://github.com/opencv/opencv/blob/0354d01e79d870adb09eea8f6d95b4093c7b4c97/modules/core/src/system.cpp

https://github.com/opencv/opencv/blob/c12243cf4fccf5df7b0270a32883986b373dca7b/modules/core/src/system.cpp

They use ANDROID instead of __ANDROID__ for the ifdef for #include <android/log.h>.

It's obviously not a linking problem (coz it's undefined identifier, not undefined reference as in the SO question).

For the error(s) you get on other version(s), we will need to know what they are exactly in order to help.

@isman7
Copy link

isman7 commented Mar 31, 2018 via email

@ZimingYuan
Copy link

Hi! I've successfully compiled OpenCV in my Termux(Android 5.0.2, aarch64), but when I tried to import it in Python3.6(import cv2), I got such an error:

Traceback (most recent call last):
File "", line 1, in
ImportError: dlopen failed: "/data/data/com.termux/files/usr/lib/python3.6/site-packages/cv/cv2.so" is 32-bit instead of 64-bit

I am wondering if I should add some compiling options of CMake to compile OpenCV into a 64-bit library but I don't know what should I add. Sincerely hope someone could offer me some help.

Thanks!

@tathastu871
Copy link
Contributor

tathastu871 commented Aug 25, 2020

With pip3 install opencv-python i got following

Pip error log

https://termbin.com/47j7v

Output log

ERROR: Command errored out with exit status 1: /data/data/com.termux/files/home/.local/share/virtualenvs/build-F0tRHWra/bin/python /data/data/com.termux/files/home/.local/share/virtualenvs/build-F0tRHWra/lib/python3.8/site-packages/pip install --ignore-installed --no-user --prefix /data/data/com.termux/files/usr/tmp/pip-build-env-ktmez8w5/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel scikit-build cmake pip 'numpy==1.11.3; python_version=='"'"'3.5'"'"'' 'numpy==1.13.3; python_version=='"'"'3.6'"'"'' 'numpy==1.14.5; python_version=='"'"'3.7'"'"'' 'numpy==1.17.3; python_version>='"'"'3.8'"'"'' Check the logs for full command output.

@tathastu871
Copy link
Contributor

tathastu871 commented Aug 26, 2020

However i managed to compile and make install but importing gave me below error:

['', '/data/data/com.termux/files/usr/lib/python38.zip', '/data/data/com.termux/files/usr/lib/python3.8', '/data/data/com.termux/files/usr/lib/python3.8/lib-dynload', '/data/data/com.termux/files/usr/lib/python3.8/site-packages', '/data/data/com.termux/files/usr/lib/python3.8/site-packages/opencv-4.4.0-py3.8.egg']                     Traceback (most recent call last):                     
   File "<stdin>", line 1, in <module>                 
    File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/opencv-4.4.0-py3.8.egg/cv2/__init__.py", line 96, in <module>                                           bootstrap()                                           File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/opencv-4.4.0-py3.8.egg/cv2/__init__.py", line 23, in bootstrap
    raise ImportError('ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.')                                             ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.

Please someone help in resolving it

Solved above error with python3 setup.py develop
But then another error came while importing which was

Traceback (most recent call last): 
 File "<stdin>", line 1, in <module>  
 File  
"/data/data/com.termux/files/home/opencv/modules/python/package/cv2/__init__.py", line 96, in <module>
    bootstrap()
 File "/data/data/com.termux/files/home/opencv/modules/python/package/cv2/__init__.py", line 58, in bootstrap
    load_first_config(['config.py'], True)
  File "/data/data/com.termux/files/home/opencv/modules/python/package/cv2/__init__.py", line 56, in load_first_config
    raise ImportError('OpenCV loader: missing configuration file: {}. Check OpenCV installation.'.format(fnames))
ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation.

@tathastu871
Copy link
Contributor

When I follow the compiling instructions listed in the wiki, and the process in the above post, I get the following error message after I run python import cv2:

ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.

In looking at OpenCV, it appears this could be due to python binding linking: opencv/opencv#13202

I'm thinking this is due to how things are stored in Termux, but I'm not familiar enough with how things are structured to do a really good job troubleshooting this.

Thoughts?

in build directory go to modules folder and python3 setup.py develop
It will solve this error

@sambit9876
Copy link

Hi,
Total noob here,I have set up @its-pointless repo but after installing opencv I get the below error.

import cv2
[libprotobuf FATAL /home/builder/termux-packages/.termux-builder/libprotobuf/src/src/google/protobuf/stubs/common.cc:87] This program was compiled against version 3.12.2 of the Protocol Buffer runtime library, which is not compatible with the installed version (3.13.0). Contact the program author for an update. If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library. (Version verification failed in "modules/dnn/opencv-caffe.pb.cc".)
terminating with uncaught exception of type google::protobuf::FatalException: This program was compiled against version 3.12.2 of the Protocol Buffer runtime library, which is not compatible with the installed version (3.13.0). Contact the program author for an update. If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library. (Version verification failed in "modules/dnn/opencv-caffe.pb.cc".)
Aborted

I tried setting up protobuf 3.12.2 but that didn't do anything. Do I have to build it from source again?

@tathastu871
Copy link
Contributor

tathastu871 commented Sep 4, 2020

I succesfully compiled build and installed opencv from source without any error. But import opencv works only in $HOME and not anywhere else. Also it seems that opencv actually not installed, because no modules whether imread, imageio nothing works it keeps saying no attribute.

Also

import opencv as cv2
cv2

Above command show

<module 'opencv' (namespace)>

No init.py there and hence complete installation is non functional.

While compiling i added python3 support but fails to work

But after cmake make and make install steps i goto opencv/modules/python folder and ran python3 setup.py install and it finally installed but then below error occured

['', '/data/data/com.termux/files/usr/lib/python38.zip', '/data/data/com.termux/files/usr/lib/python3.8', '/data/data/com.termux/files/usr/lib/python3.8/lib-dynload', '/data/data/com.termux/files/usr/lib/python3.8/site-packages', '/data/data/com.termux/files/usr/lib/python3.8/site-packages/opencv-4.4.0-py3.8.egg']                     Traceback (most recent call last):                     
   File "<stdin>", line 1, in <module>                 
    File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/opencv-4.4.0-py3.8.egg/cv2/__init__.py", line 96, in <module>                       
 bootstrap()                                       
File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/opencv-4.4.0-py3.8.egg/cv2/__init__.py", line 23, in bootstrap raise ImportError('ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.')               

  ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.

Also tried recompiling with -DOPENCV_SKIP_PYTHON_LIADER=ON but same error

Also tried python setup.py develop but no success
Please someone help in resolving it

Please help needed

@eusoubrasileiro
Copy link

Thank you @its-pointless and @xeffyr perfectly working on my Xiomi Mibox S Android 9.

@ABIRHOSSAIN10
Copy link

I used this command in termux but not working
When i used this first time its work but now its not working

curl -LO https://its-pointless.github.io/setup-pointless-repo.sh
bash setup-pointless-repo.sh
pkg install opencv

Error
Traceback (most recent call last):
File "/storage/emulated/0/sketch.py", line 9, in
import cv2
ModuleNotFoundError: No module named 'cv2

@Yisus7u7
Copy link
Contributor

Yisus7u7 commented Oct 9, 2021

Must be upgraded to python 3.10

@maklimcz
Copy link

maklimcz commented Oct 24, 2021

Hi, I am also getting the same message like @ABIRHOSSAIN10
@Yisus7u7 python version is 3.10.0
my device is Samsung Galaxy S8 (exynos)
I have performed following steps:

curl -LO https://its-pointless.github.io/setup-pointless-repo.sh
bash setup-pointless-repo.sh
pkg install opencv

as a regular user (not a root)
Screenshot_20211025-012523_Termux

edit: now i get it, the its-pointless repo contains opencv for python 3.9, but the lastest is 3.10 and this one is present in temrux repo

@stale
Copy link

stale bot commented Dec 10, 2021

This issue/PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix Issue won't be fixed label Dec 10, 2021
@stale stale bot closed this as completed Dec 24, 2021
@SamYokai
Copy link

Hi, I am also getting the same message like @ABIRHOSSAIN10 @Yisus7u7 python version is 3.10.0 my device is Samsung Galaxy S8 (exynos) I have performed following steps:

curl -LO https://its-pointless.github.io/setup-pointless-repo.sh
bash setup-pointless-repo.sh
pkg install opencv

as a regular user (not a root) Screenshot_20211025-012523_Termux

edit: now i get it, the its-pointless repo contains opencv for python 3.9, but the lastest is 3.10 and this one is present in temrux repo

may I ask how you downgrade python version from 3.10 to 3.9? because I also python 3.10 and want to try. By the way actually starting I install python 3.9.7 but when I bash setup-pointless-repo.sh then it automatic upgrade my python to 3.10...

@SamYokai
Copy link

Sorry for asking, I would like to ask that actually how to install opencv in termux which can python import and use? because I follow the step which curl the its-pointless repo and bash then pkg install but only in pkg list and haven't in pip list. I also try other method which had found from previous comment but still not working. But I use same way to install numpy and scipy no problem, both of these can found in pip list, just except opencv. Anyone can help me? Im using Android 7.1.1, Termux 0.115, Python 3.9.7

@maklimcz
Copy link

Hi, I did not manage to install opencv. The building it from sources was failing and I couldn't solve that. Since then I haven't looked if sth changed.

@SamYokai
Copy link

Hi, I did not manage to install opencv. The building it from sources was failing and I couldn't solve that. Since then I haven't looked if sth changed.

oh I see, never my its ok, now I also face the problem, but for your problem I think you can try with Python 3.9 except from 3.10 since for what I know this repo the latest is Python 3.9 and haven't yet prepare for Python 3.10.
But my problem is more make me curious, haha, since I using Python 3.9 and I try install for numpy, scipy and opencv since these three can get and use same method with the its-pointless-repo, then what I get is numpy and scipy can succes found in pip list and python import also no problem, but only opencv cannot be found in python. This problem make me curious to myself. haha

@maklimcz
Copy link

Please let me know if you manage to run python and opencv to use device camera (preferably without root)

@xtkoba xtkoba added python Issue is about Python related stuff, including pip and removed wontfix Issue won't be fixed labels Feb 24, 2022
@xtkoba xtkoba reopened this Feb 24, 2022
@gety9
Copy link

gety9 commented Mar 15, 2022

@xtkoba

does your #9369 commit suppose to fix the issue?

i still can't pip install opencv-python

getting following error:

is not able to compile a simple test program.

              It fails with the following output:

                Change Dir: /data/data/com.termux/files/usr/tmp/pip-install-30n3sd40/cmake_4a900bba224f4e84ae752a1746ccdf9d/_skbuild/linux-aarch64-3.10/cmake-build/CMakeProject-build/CMakeFiles/CMakeTmp
                                                                                         Run Build Command(s):/data/data/com.termux/files/usr/bin/ninja cmTC_75cca && [1/2] Building C object CMakeFiles/cmTC_75cca.dir/testCCompiler.c.o
                [2/2] Linking C executable cmTC_75cca                                    FAILED: cmTC_75cca                                                       : && /data/data/com.termux/files/usr/bin/cc -D_POSIX_C_SOURCE=199506L -D_POSIX_SOURCE=1 -D_SVID_SOURCE=1 -D_BSD_SOURCE=1  -O2 -g -DNDEBUG -lstdc++ -lgcc -lrt CMakeFiles/cmTC_75cca.dir/testCCompiler.c.o -o cmTC_75cca   && :                                                                      ld.lld: error: unable to find library -lgcc                              clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

(error is at very end of above code, error: unable to find library -lgcc)

@Grimler91
Copy link
Member

@gety9 linked commit adds it as a termux package, so install through pkg: pkg install opencv-python

@gety9
Copy link

gety9 commented Mar 15, 2022

@Grimler91 thanks for quick reply,

it worked, and opencv-python is seems to be installed:

Use 'apt autoremove' to remove it.
The following NEW packages will be installed:
  opencv-python
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/887 kB of archives.
After this operation, 4870 kB of additional disk space will be used.
Selecting previously unselected package opencv-python.
(Reading database ... 31044 files and directories currently installed.)
Preparing to unpack .../opencv-python_4.5.5-1_aarch64.deb ...
Unpacking opencv-python (4.5.5-1) ...
Setting up opencv-python (4.5.5-1) ...
Requirement already satisfied: numpy in /data/data/com.termux/files/usr/lib/python3.10/site-packages (1.22.2)

however when i try to install pip install table_ocr

(that's the package i need opencv-python for)

it starts to build opencv-python again:

pip install table_ocr
Collecting table_ocr
  Downloading table_ocr-0.2.5-py3-none-any.whl (33.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 33.4/33.4 MB 12.9 MB/s eta 0:00:00
Collecting pytesseract~=0.3
  Downloading pytesseract-0.3.9-py2.py3-none-any.whl (14 kB)
Requirement already satisfied: numpy~=1.19 in /data/data/com.termux/files/usr/lib/python3.10/site-packages (from table_ocr) (1.22.2)
Collecting opencv-python~=4.2
  Downloading opencv-python-4.5.5.64.tar.gz (89.9 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 89.9/89.9 MB 7.2 MB/s eta 0:00:00
  Installing build dependencies

could you please help me understand what i am doing wrong? how to make it accept already installed opencv-python?

@GalaxySnail
Copy link
Contributor

GalaxySnail commented Mar 25, 2022

$ dpkg -c ./opencv-python_4.5.5-1_aarch64.deb | awk '{print $6}' | tree --fromfile
data
└── data
    └── com.termux
        └── files
            └── usr
                └── lib
                    └── python3.10
                        └── site-packages
                            └── cv2
                                ├── __init__.py
                                ├── config-3.10.py
                                ├── config.py
                                ├── gapi
                                │   └── __init__.py
                                ├── load_config_py2.py
                                ├── load_config_py3.py
                                ├── mat_wrapper
                                │   └── __init__.py
                                ├── misc
                                │   ├── __init__.py
                                │   └── version.py
                                ├── python-3.10
                                │   └── cv2.cpython-310.so
                                └── utils
                                    └── __init__.py

15 directories, 11 files

I think something like opencv_python-4.5.5.64.dist-info directory is missing in site-packages. See: PEP 376, PEP 627, and this link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Issue is about Python related stuff, including pip
Projects
None yet
Development

Successfully merging a pull request may close this issue.