While building from source with the settings below I get both config.py and config-3.10.py.
PYTHON3_EXECUTABLE …
PYTHON3_INCLUDE_DIR …
PYTHON3_LIBRARY …
BUILD_SHARED_LIBS OFF
OPENCV_ENABLE_NONFREE ON
OPENCV_EXTRA_MODULES_PATH …
BUILD_opencv_world OFF
But while building from source with the settings below config.py is generated but config-3.10.py is not generated.
PYTHON3_EXECUTABLE …
PYTHON3_INCLUDE_DIR …
PYTHON3_LIBRARY …
BUILD_SHARED_LIBS OFF
OPENCV_ENABLE_NONFREE ON
OPENCV_EXTRA_MODULES_PATH …
BUILD_opencv_world ON
Therefore when I want to import cv2 in Python I get the error:
so, this makes all the difference ?
if it leads to a wrong configuration, it probably should get reported
however:
it is set to OFF by default (why did you change it ?)
it is irrelevant (or , should be !) for the python bindings in general
(if it’s ON, c++ libs will be merged to a single, fat one)
you correctly set BUILD_SHARED_LIBS=OFF, so it should link to the c++ libs statically, no matter if it’s 15 small or a single big one
The reason why I generate BUILD_opencv_world is in forums I observed that it is a commonly used method to enable BUILD_opencv_world.
When BUILD_opencv_world is enabled you do not need to look for which .dll should be included for different opencv functions.
Even if it is irrelevant, I think enabling BUILD_opencv_world prevents python3 bindings from being successfully built.
When I search for this error I observe others facing the same problem.
I can share the links if you want?
Which OS are you on I have no issues with OpenCV World on Ubuntu and Windows when generating python bindings. That said I don’t usually go for a static build.
Are you sure this is the issue and its not just that you haven’t cleaned your build directory after the first configuration?
you can see the exact CMake configuration commands I used. I will check now against the latest version of OpenCV to make sure the installation still works.
Note I always use the command line and not the GUI that way I can easily share my CMake configuration commands with others when I encounter issues/bugs.
I just want to note that I am building OpenCV from source for a PC that does note have GPU.
I am only changing the settings that I mention at the beginning of the topic.
adding -DBUILD_opencv_world=ON and filling in the parameters as specified and it built OpenCV world and installed the python bindings to the site-packages directory.
I can then import cv2 without any errors. I even deleted the cv2 directory and installed a second time and everything still worked so I’m not sure what your issue is, maybe its because you don’t specify PYTHON3_PACKAGES_PATH. If you need futher assistance use the CMake command line and post the exact arguments you are using including the ouput from the configuration stage.
Using the command line, I tried to build opencv from source as you suggested.
I observe that config-3.10.py is being generated.
However, the number of the folders in cv2 folder is 4.
When I built with “BUILD_opencv_world OFF” the number of folders in the cv2 folder was 61.
Should DPYTHON3_PACKAGES_PATH point the folder in my environment or can I select any folder?
Another thing to note is that there is no DBUILD_opencv_python3 property in CMAKE GUI.
In the command line, if I remove -DBUILD_opencv_python3=ON config-3.10.py is not generated.
Actually, site-packages directory does not contain cv2 module(folder) initially since the environment does not contain opencv before built.
After building from source code, cv2 folder is generated.
For the builts with BUILD_SHARED_LIBS OFF, I get linker errors.
When I add all .lib files to Additional Dependencies in Visual Studio Linker configurations the number of linker errors I get decreases. However, the number of linker errors does not become 0.
For the builts with BUILD_SHARED_LIBS OFF, should I add more configuration parameters for cmake?
I don’t have any issues on Windows 11 building the latest commit of OpenCV from the 4.x branch with those commands, maybe the CMake config output and the first linker errors you encounter will shed some light on the issue.
What about Visual Studio settings?
I am setting include directory and lib directory.
For debug and release I am setting proper world .lib files.
Should I do more settings for BUILD_SHARED_LIBS=OFF?
There are similar discussions without a definite answer.
So eventhough I use .lib files do I still need some opencv .dll?
If so maybe my error is related to not changing the environment variables.
This would be nice because it means no error in the built process.
However, when I observe the bin folder under install there are a couple of .exe files but there is only one .dll which is opencv_videoio_ffmpeg480_64.dll
For Python bindings, the following configuration is fine
The configuration is also fine for C++ release.
However, for C++ debug I get the error indicating that python310_d.lib is not accessible.
That is because conda environments does not include python debug libraries.
I used pure Python installer(not conda) and selected to generate debug libraries.
Somehow the same file is not found by the installer.
Since I use conda as development environment I decided to go for 2 opencv from source builts.
One for python and one for C++(both debug and release).
Having 2 saperate builts does not hurt in my opinion.
Ignore my previous answer (which I’ve deleted for clarity). I misread your post.
Yes if you want to read media file with VideoCapture and the FFMpeg backend. OpenCV uses plugins for this.
It would be helpful to understand where you are coming from if you posted the error.
This is fine but you can easily work around this and use a debug build for both by modifying two lines in your pyconfig.h as described in the guide I wrote.