[Python API] quick fix of packaging#8870
Conversation
8e7a38f to
0ac4989
Compare
0ac4989 to
3f507c7
Compare
e15982b to
7480e05
Compare
ff724cf to
ad84670
Compare
| from openvino.runtime.impl import PartialShape | ||
| from openvino.runtime.impl import Layout | ||
|
|
||
| from openvino.runtime.ie_api import Core |
There was a problem hiding this comment.
Could you try to create "root" aliases?
from openvino.runtime.ie_api import Core
+openvino.Core = CoreThis should repair from openvino import Core
To have openvino symbol please try:
openvino = sys.modules['openvino']- or just
import openvino(in general it returns cached value fromsys.modules)
BTW, Do we have import openvino.Core somewhere?
There was a problem hiding this comment.
@alalek ok, thank you, I'll try it.
BTW, Do we have import openvino.Core somewhere?
As I know and as I saw in files, no, we don't have import openvino.Core
There was a problem hiding this comment.
@alalek ok, I've tried to add openvino.Core = Core inside openvino/runtime/__init__.py and also openvino = sys.modules['openvino']
There was a problem hiding this comment.
Looks like the root __init__.py doesn't really import sub-packages during initialization (please add some debug "print" into runtime/__init__.py to check that).
Can we add dummy subpackages for Core, Tensor, etc?
openvino/Core/__init__.py:
import openvino
from openvino.runtime.ie_api import Core
openvino.Core = Core
del sys.modules['openvino.Core']
Need to check that these cases work with workaround:
import openvino.Corefrom openvino import Core
There was a problem hiding this comment.
We could initialize sub-packages using the walk_packages approach (available in Python 3.0+ at least)
Root openvino/__init__.py:
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
+def _subpackage_import_error(name):
+ print("WARN: Error importing sub-package '%s'" % name)
+ pass
+
+for module_info in __import__('pkgutil').walk_packages(__path__, __name__ + '.', onerror=_subpackage_import_error):
+ print(module_info.name)
+ passThere was a problem hiding this comment.
@alalek
I may try but looks like other subpackages like accuracy_checker should also add these lines.
Also one small doubt came from here: https://packaging.python.org/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages
The __init__.py file for the namespace package needs to contain only the following:
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
As I know, the code after this line is inaccessible.
BTW, this PR is like quick fix to unblock all, I'll continue to make from openvino import Core work here: #8846
There was a problem hiding this comment.
the code after this line is inaccessible.
My local print() experiment shows that code before and after this line runs properly.
There is no anything special - just regular Python code.
However it it critical that all openvino/__init__.py files must have the same content. Including AC.
if we need to initialize "runtime" only (and we perform all necessary initialization in runtime/__init__.py), then this would be enough (without walk_packages):
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
+__import__(__name__ + '.runtime') # force initializationAC possible workaround for __init__:
- use
openvino->openvino_toolspackage - AC's
openvino_tools/__init__.py- no special requirements except.extend_path() - OV's
openvino/__init__.py: add second "extend_path" line:__path__ = __import__('pkgutil').extend_path(__path__, __name__) +__path__ = __import__('pkgutil').extend_path(__path__, 'openvino_tools') +__import__(__name__ + '.runtime')
Verify (not sure about AC actual name):
import openvino.accuracy_checkerfrom openvino import accuracy_checkerimport openvinowithout installedopenvino_tools
| from openvino import Core, Tensor | ||
| from openvino.impl import Function | ||
| from openvino.runtime import Core, Tensor | ||
| from openvino.runtime.impl import Function |
There was a problem hiding this comment.
from openvino.runtime.impl import Function
src/bindings/python/src/openvino/runtime/__init__.py file has this:
from openvino.runtime.impl import Function
and we don't have __all__ there.
So, this should work:
-from openvino.runtime.impl import Function
+from openvino.runtime import Functionor with aliases above
-from openvino.runtime.impl import Function
+from openvino import Functionwith the similar result.
There was a problem hiding this comment.
from openvino.runtime import Core, Tensor, Function
To make this line work and import all 3 elements we also need to add in runtime/__init__.py (besides of added openvino.Core = Core):
openvino.Tensor = Tensor
openvino.Function = Function
There was a problem hiding this comment.
@alalek I just wanted to make sure that this way would help with Core import. If it helped me, I'd add the rest classes.
BTW, still I need to import firstly openvino.runtime, only after that from openvino import Core works. So looks like when the user call import openvino, only openvino/__init__.py is initialized while openvino/runtime/__init__.py will be initialized after direct call of import openvino.runtime.
Look at the comment above
There was a problem hiding this comment.
but it works as it imports like from openvino.runtime
There was a problem hiding this comment.
I agree that we need try to check one part first.
I expected this diff (from initially commented patch):
-from openvino.runtime import Core, Tensor
+from openvino import Core
+from openvino.runtime import Tensor
from openvino.runtime.impl import FunctionBTW, Could you please add link to builder which contains logs for these lines?
only
openvino/__init__.pyis initialized
Looks like you are right (please check separate thread above).
cfa1659 to
a330706
Compare
a330706 to
5096c1a
Compare

Details:
from openvino.runtime import CoreTickets: