Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python module: replace config.py files by config.ini#16008

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

@tpetazzoni
Copy link

The OpenCV Python module currently installs and reads at runtime a config.py file and a config-X.Y.py file to retrieve some bits of configuration. This is done using the execfile() Python mechanism, which unfortunately only works with .py files, and not with .pyc files.

However, on some embedded systems, only .pyc files are installed: they are already byte-compiled, which optimizes the startup time, and installating both .pyc and .py files doubles the storage space, which is a limited resource on embedded systems.

In addition, loading .py file requires different code between Python 2 and Python 3.

To solve these issues, this pull request replaces the .py files by .ini files, which can trivially be parsed by the standard ConfigParser Python module.

…ATH_RELATIVE_CONFIGCMAKE when not neededThe variable OpenCV_PYTHON_INSTALL_PATH_RELATIVE_CONFIGCMAKE is set inthe if(IS_ABSOLUTE ...), but it is not used anywhere afterwards.A variable of the same name is defined and used in the else() clauseof the same condition, but it is only used within that else() clause.Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
The cv2 Python modules currently reads at runtime some bits ofconfiguration from config.py and config-X.Y.py files, by executingthem using execfile() or similar inside the Python interpreter.Unfortunately, this requires having the .py files themselvesavailable, which may not be the case on embedded systems where onlythe byte-compiled .pyc files are present (the .pyc files are alreadybyte-compiled, and in order to be space-efficient, .py files are notinstalled on some embedded systems).Due to the lack of .py files, importing the cv2 Python modulefails. Since this configuration mechanism is a bit unusual, and alsorequires separate handling for Python 2 and Python 3, this commitreplaces it by using two .ini files, which are generated with the sameinformation as the .py files, but parsed using the standardConfigParser module of Python.config.ini looks like this:[python]binpath = /usr/libwhile config-3.8.ini looks like this:[python]extensionpath = /usr/lib/python3.8/site-packages/cv2/python-3.8If multiple paths are present, they are stored colon-separated, andthey are split again when the configuration files are parsed.The only change relevant mentioning is that the expansion ofLOADER_DIR is now done when the configuration is parsed: if we have anabsolute path, we take it as-is, if there is a relative path, weassume it is relative to LOADER_DIR.Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
'''
importos
importsys
importconfigparser
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

In Python2 it is namedConfigParser.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ah, yes, thank you, indeed.

@VadimLevin
Copy link
Contributor

Thanks for you contribution!
@tpetazzoni Do you have any chance to proceed work on this PR?

@asmorkalov
Copy link
Contributor

@tpetazzoni any progress on the patch?

@tpetazzoni
Copy link
Author

@asmorkalov No sorry, not yet, I'll try to get to it.

@alalek
Copy link
Member

on some embedded systems, only .pyc files are installed

Consider disabling OpenCV Python bindings loader in your configuration:cmake -DOPENCV_SKIP_PYTHON_LOADER=ON ...

Perhaps .ini files will not work for us. In the future we want to detect Python distributions in runtime, like Anaconda Python, Intel Python distribution, etc. One package + auto detection/configuration through .py files config.

Instead of .ini approach you may take a look in direction of changing of importing approach (use some "import" code instead of "execfile")

@asmorkalov
Copy link
Contributor

OpenCV team decided to close the PR as expected behavior is reachable with-DOPENCV_SKIP_PYTHON_LOADER=ON option in CMake. See alalek's comment above.

@tpetazzoni
Copy link
Author

Well, OPENCV_SKIP_PYTHON_LOADER may not be an option: some people do want the Python bindings of OpenCV available on their embedded system.

@alalek
Copy link
Member

OPENCV_SKIP_PYTHON_LOADER doesn't disable OpenCV Python bindings itself.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@mshabuninmshabuninmshabunin left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@tpetazzoni@VadimLevin@asmorkalov@alalek@mshabunin

[8]ページ先頭

©2009-2025 Movatter.jp