Update __init__.py to support symbolic links#19908
Conversation
alalek
left a comment
There was a problem hiding this comment.
I believe, this patch should not break anything in general.
As I understand from the problem description, configuration files try to refer on files outside of Python installation location (through parent directories, and these extra files are not installed).
For such cases, it makes sense to install cv2 package with all necessary dependencies into the target package directory (with modified config files for specific layout).
Currently, the LOADER_DIR is set as os.path.dirname(os.path.abspath(__file__)). This does not point to the true library path if the cv2 folder is symlinked into the Python package directory such that importing cv2 under Python fails. The proposed change only resolves symbolic links correctly by calling os.path.realpath(__file__) first and does not change anything if __file__ contains no symbolic link.
|
This patch should go into 3.4 branch first. Please:
Note: no needs to re-open PR, apply changes "inplace". |
|
I tried to follow these steps, however there was some weird stuff in the commit besides the Python script and while trying to fix it, it seems that I pretty much messed up the PR. Whats the right way to fix this? |
Currently, the LOADER_DIR is set to os.path.dirname(os.path.abspath(file)). This does not point to the true library path if the cv2 folder is symlinked into the Python package directory such that importing cv2 under Python fails. The proposed change only resolves symbolic links correctly by calling os.path.realpath(file) first and does not change anything if file contains no symbolic link.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.