openvinotoolkit / openvino

OpenVINO™ is an open-source toolkit for optimizing and deploying AI inference
https://docs.openvino.ai
Apache License 2.0
7.33k stars 2.29k forks source link

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

Open drimyus opened 7 months ago

drimyus commented 7 months ago

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

ilya-lavrenov commented 7 months ago

Could you please try:

python3 -c "import openvino; print(openvino.__version__)"
p-wysocki commented 7 months ago

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?

drimyus commented 7 months ago

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 commented 7 months ago

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.

ilya-lavrenov commented 7 months ago

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)

drimyus commented 7 months ago

@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
ilya-lavrenov commented 7 months ago

Have you installed libpython3.10 ?

drimyus commented 7 months ago

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 commented 7 months ago

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'
Wovchena commented 6 months ago

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).

hagabb commented 6 months ago

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
Wovchena commented 6 months ago

@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.

ilya-lavrenov commented 6 months ago

@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

hagabb commented 6 months ago

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

ilya-lavrenov commented 5 months ago

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

hagabb commented 5 months ago

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.

zoechi commented 1 month ago

I have no idea if this helps anyone, but I run into the same error in NixOS. I installed openvino-dev and tried to also install openvino using direnv.nix which uses some kind of virtual environment.

Installing openvino as Nix system package (pkgs.python312Packages.openvino) solved the error.

My devenv config to make omz_downloader and omz_converter succeed:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    # nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    systems.url = "github:nix-systems/default";
    devenv.url = "github:cachix/devenv";

  };

  # Currently broken for fish https://github.com/direnv/direnv/issues/1022
  # nixConfig = {
  #   extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
  #   extra-substituters = "https://devenv.cachix.org";
  # };

  outputs = {
    self,
    nixpkgs,
    devenv,
    systems,
    fenix,
    ...
  } @ inputs: let
    forEachSystem = nixpkgs.lib.genAttrs (import systems);
  in {
    formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.alejandra;

    packages = forEachSystem (system: {
      devenv-up = self.devShells.${system}.default.config.procfileScript;
    });

    devShells = forEachSystem (system: let
      pkgs = nixpkgs.legacyPackages.${system};
    in {
      default = devenv.lib.mkShell {
        inherit inputs pkgs;

        modules = [
          {
            env = {
              LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib";
            };

            packages = [
              pkgs.python311Packages.openvino
            ];

            languages = {
              nix.enable = true;
              python = {
                package = pkgs.python311; # tensorflow doesn't support Python 3.12 yet
                enable = true;
                venv.enable = true;
                venv.requirements = ''
                fastjsonschema
                # openvino
                openvino-dev
                tensorflow
                '';
              };
            };
          }
        ];
      };
    });
  };
}
vankhoa01 commented 2 weeks ago

Hi my friends, I have same issue on Mac M3 (python 3.10). Did you have solution to fix this ?

Screenshot 2024-11-06 at 6 11 48 PM