Closed tedski closed 4 years ago
This is an issue with the virtual environment. I cannot reproduce this outside of the virtual environment, therefore I cannot reliably say this is an issue with opencv-python. I believe this is an issue with adding some FindPython hints to CMAKE_ARGS in order to properly build.
It looks like OpenCV's Cmake script found some Java on your machine but failed to compile the java wrapper and failed the whole build. You could disable java via cmake args, I'll see if it makes sense to disable it in setup.py directly.
One thing I observed that was interesting and may be useful to you is that when building opencv-python
using pip wheel .
, the jar directory (/tmp/pip-req-build-x6z899pg/_skbuild/linux-x86_64-3.6/cmake-build/bin/
in this issue) was not created. However, when building the upstream opencv
repo it was. As a workaround during investigation, I patched one of the CMake files as so:
diff --git a/modules/java/jar/CMakeLists.txt b/modules/java/jar/CMakeLists.txt
index 33817bcc62..f302d46ca1 100644
--- a/modules/java/jar/CMakeLists.txt
+++ b/modules/java/jar/CMakeLists.txt
@@ -9,6 +9,7 @@ file(MAKE_DIRECTORY "${OPENCV_JAVA_DIR}/build/classes")
set(java_src_dir "${OPENCV_JAVA_DIR}/java")
file(MAKE_DIRECTORY "${java_src_dir}")
+file(MAKE_DIRECTORY "${OpenCV_BINARY_DIR}/bin")
set(JAR_NAME opencv-${OPENCV_JAVA_LIB_NAME_SUFFIX}.jar)
set(OPENCV_JAR_FILE "${OpenCV_BINARY_DIR}/bin/${JAR_NAME}" CACHE INTERNAL "")
This worked around the jar building issue, but it seems odd that I would have this issue and others wouldn't.
I tried disabling java and I have a new flavor of error:
$ echo $CMAKE_ARGS
-DBUILD_opencv_java=OFF
$ echo $ENABLE_HEADLESS
1
$ python3 setup.py sdist --formats=gztar
[SNIP]
$ pip install dist/opencv-python-headless-4.3.0+914404d.tar.gz
[SNIP]
Successfully built opencv-python-headless
Installing collected packages: opencv-python-headless
Attempting uninstall: opencv-python-headless
Found existing installation: opencv-python-headless 4.3.0+914404d
Uninstalling opencv-python-headless-4.3.0+914404d:
Created temporary directory: /home/tstrzalk/venvs/opencv/lib/python3.7/site-packages/~v2
Removing file or directory /home/tstrzalk/venvs/opencv/lib/python3.7/site-packages/cv2/
Created temporary directory: /home/tstrzalk/venvs/opencv/lib/python3.7/site-packages/~pencv_python_headless-4.3.0+914404d.dist-info
Removing file or directory /home/tstrzalk/venvs/opencv/lib/python3.7/site-packages/opencv_python_headless-4.3.0+914404d.dist-info/
Successfully uninstalled opencv-python-headless-4.3.0+914404d
Successfully installed opencv-python-headless-4.3.0+914404d
Seems like it worked, but I get an error on import:
>>> import cv2
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-c8ec22b3e787> in <module>()
----> 1 import cv2
~/src/opencv-python/cv2/__init__.py in <module>()
3 import sys
4
----> 5 from .cv2 import *
6 from .data import *
7
ModuleNotFoundError: No module named 'cv2.cv2'
The jar directory was not probably created because we generate here only the Python bindings, nothing else.
The other issue you are having is caused by the fact that you are trying to import the package in the same directory where there original sources are (note the script path). Python always searches for packages from the current directory first and after that from the environment. Just go to some other directory and try again.
🤦 That's right. I got lost in the weeds there. Building without java enabled worked well.
Expected behaviour
Following the manual build process to build on RHEL7 should work as documented.
Actual behaviour
Build fails with a failure related to
opencv-430.jar
.Steps to reproduce
example code
operating system Red Hat Enterprise Linux Workstation release 7.6 (Maipo)
architecture (e.g. x86) x86_64
opencv-python version master
Issue submission checklist
[x] This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)
[x] I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)
opencv-python