openvino icon indicating copy to clipboard operation
openvino copied to clipboard

[Bug]: ImportError: cannot import name 'Core' from 'openvino' after model_zoo installation

Open drimyus opened this issue 10 months ago • 11 comments

OpenVINO Version

2024.0.0

Operating System

Other (Please specify in description)

Device used for inference

CPU

Framework

None

Model used

No response

Issue description

ImportError: cannot import name 'Core' from 'openvino'

OS: ubuntu 22.04 openvino: 2024.0.0 installed using pypi pip3 install openvino~=2024.0.0 python: python3.10

I followed instruction document to install openvino(2024.0.0), but failed to import sub modules.

source venv/bin/activate

(venv) python -m pip install --upgrade pip
(venv) python -m pip install openvino~=2024.0.0

(venv) python -c "from openvino import Core; print(Core().available_devices)"

ImportError: cannot import name 'Core' from 'openvino' (/{venv_path}/lib/python3.10/site-packages/openvino/__init__.py)

Step-by-step reproduction

No response

Relevant log output

source venv/bin/activate

(venv) python -m pip install --upgrade pip
(venv) python -m pip install openvino~=2024.0.0

(venv) python -c "from openvino import Core; print(Core().available_devices)"

ImportError: cannot import name 'Core' from 'openvino' (/{venv_path}/lib/python3.10/site-packages/openvino/__init__.py)

Issue submission checklist

  • [X] I'm reporting an issue. It's not a question.
  • [X] I checked the problem with the documentation, FAQ, open issues, Stack Overflow, etc., and have not found a solution.
  • [X] There is reproducer code and related data files such as images, videos, models, etc.

drimyus avatar Apr 08 '24 10:04 drimyus

Could you please try:

python3 -c "import openvino; print(openvino.__version__)"

ilya-lavrenov avatar Apr 08 '24 11:04 ilya-lavrenov

Could you please make sure your PYTHONPATH environment variable doesn't point to anything that could be OpenVINO related? Which version of pip are you using?

p-wysocki avatar Apr 08 '24 11:04 p-wysocki

openvino version is 2024.0.0

pip3 list| grep openvino

openvino                 2024.0.0
openvino-dev             2024.0.0
openvino-telemetry       2023.2.1

pip3 version 24.0

pip3 --version

pip 24.0 from /{venv_path}/lib/python3.10/site-packages/pip (python 3.10)

drimyus avatar Apr 08 '24 12:04 drimyus

Could you please try:

python3 -c "import openvino; print(openvino.__version__)"
python3 -c "import openvino; print(openvino.__version__)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'openvino' has no attribute '__version__'

But I can see openvino in pip3 list.

drimyus avatar Apr 08 '24 12:04 drimyus

Could you please reinstall openvino? Looks like /{venv_path}/lib/python3.10/site-packages/openvino does not contain any file (or does not contain __init__.py at least)

ilya-lavrenov avatar Apr 08 '24 13:04 ilya-lavrenov

@ilya-lavrenov when I checked the openvino folder in venv, I can get this list like below

$ ls venv/lib/python3.10/site-packages/openvino
frontend  __init__.py  model_zoo                 preprocess  __pycache__                                  runtime  torch
helpers   libs         _offline_transformations  properties  _pyopenvino.cpython-310-x86_64-linux-gnu.so  tools    utils.py

drimyus avatar Apr 08 '24 16:04 drimyus

Have you installed libpython3.10 ?

ilya-lavrenov avatar Apr 08 '24 16:04 ilya-lavrenov

Yes, I have installed python3.10

$ sudo apt install libpython3.10
[sudo] password for tk: 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
libpython3.10 is already the newest version (3.10.12-1~22.04.3).
libpython3.10 set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 21 not upgraded.

drimyus avatar Apr 08 '24 17:04 drimyus

Let me update the Issue description

First I installed openvino==2024.0.0 in empty venv, it worked fine But when I tried to install (model_zoo api package)[https://github.com/openvinotoolkit/open_model_zoo/blob/master/demos/common/python/model_zoo/model_api/README.md#installing-python-model-api-package] in same venv, the issue occurred

ImportError: cannot import name 'Core' from 'openvino'

drimyus avatar Apr 08 '24 18:04 drimyus

I can't reproduce the issue:

python3 -m venv venv
source ./venv/bin/activate
python -m pip install -U pip
python -m pip install openvino==2024.0.0
python -m pip install demos/common/python
python -c "from openvino import Core; print(Core().available_devices)"

I tried both 2024.0.0 (https://github.com/openvinotoolkit/open_model_zoo/commit/37f60eb7fe1dcdedc552b2fb184d646723ed5e80) and master (https://github.com/openvinotoolkit/open_model_zoo/commit/9c6d95a2a668d6ae41aebda42b15608db7dd3fa0).

Wovchena avatar Apr 30 '24 12:04 Wovchena

I was getting the same ImportError on Windows 11 Enterprise, but installing the VC++ runtime components (specifically, vc_redist.x64.exe) fixed the problem. Is there an equivalent module of runtime components for Linux?

Before installing vc_redist.x64:

C:\Users\sdp>python --version
Python 3.11.9
C:\Users\sdp>python -m venv openvino_env
C:\Users\sdp>openvino_env\Scripts\activate
(openvino_env) C:\Users\sdp>python -m pip install --upgrade pip
...
(openvino_env) C:\Users\sdp>pip install openvino==2024.1.0
...
(openvino_env) C:\Users\sdp>python -c "from openvino import Core; print(Core().available_devices)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'Core' from 'openvino' (C:\Users\sdp\openvino_env\Lib\site-packages\openvino\__init__.py)

After installing vc_redist.x64:

(openvino_env) C:\Users\sdp>python -c "from openvino import Core; print(Core().available_devices)"
['CPU', 'NPU']

(openvino_env) C:\Users\sdp>python -c "import openvino; print(openvino.__version__)"
2024.1.0-15008-f4afc983258-releases/2024/1

hagabb avatar May 21 '24 20:05 hagabb

@jiwaszki, It seems Python OpenVINO depends on Visual Studio being installed (2019 or just https://www.microsoft.com/en-in/download/details.aspx?id=48145). I don't really know how to verify that so we could describe it in the docs. Maybe you have some ideas.

Wovchena avatar May 25 '24 13:05 Wovchena

@jiwaszki, It seems Python OpenVINO depends on Visual Studio being installed (2019 or just https://www.microsoft.com/en-in/download/details.aspx?id=48145). I don't really know how to verify that so we could describe it in the docs. Maybe you have some ideas.

It depends on MSVC runtime (vs_redist). It's highlighted in PyPi OpenVINO page: image

ilya-lavrenov avatar May 25 '24 13:05 ilya-lavrenov

This issue was originally reported on Linux, where OpenVINO requires the GNU development tools. Installing GCC 7.5 may fix this problem on Linux.

openvino_sys_reqs

hagabb avatar May 28 '24 18:05 hagabb

Do you use Python 3.8? If yes, you also need to install libpython3.8 (which seems to be transitively installed by gcc 7.5 as well) image

ilya-lavrenov avatar May 30 '24 09:05 ilya-lavrenov

I'm using Python 3.11 on Windows 11 Enterprise. This issue was originally reported for Python 3.10 on Linux. However, the underlying cause appears similar.

hagabb avatar May 30 '24 13:05 hagabb