PaddleOCR: Cannot import paddleocr together with yolov8

  • Windows 11
  • paddleocr 2.6.1.3
import paddleocr
import ultralytics
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\ultralytics\__init__.py", line 5, in <module>
    from ultralytics.hub import start
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\ultralytics\hub\__init__.py", line 5, in <module>
    from ultralytics.hub.auth import Auth
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\ultralytics\hub\auth.py", line 5, in <module>
    from ultralytics.hub.utils import HUB_API_ROOT, PREFIX, request_with_credentials
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\ultralytics\hub\utils.py", line 14, in <module>
    from ultralytics.yolo.utils import (ENVIRONMENT, LOGGER, ONLINE, RANK, SETTINGS, TESTS_RUNNING, TQDM_BAR_FORMAT,
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\ultralytics\yolo\__init__.py", line 3, in <module>
    from . import v8
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\ultralytics\yolo\v8\__init__.py", line 3, in <module>
    from ultralytics.yolo.v8 import classify, detect, pose, segment
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\ultralytics\yolo\v8\classify\__init__.py", line 3, in <module>
    from ultralytics.yolo.v8.classify.predict import ClassificationPredictor, predict
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\ultralytics\yolo\v8\classify\predict.py", line 3, in <module>
    import torch
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\torch\__init__.py", line 202, in <module>
    from torch._C import *  # noqa: F403
RuntimeError: generic_type: type "_CudaDeviceProperties" is already registered!
import ultralytics
import paddleocr
Error: Can not import paddle core while this file exists: C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddle\fluid\libpaddle.pyd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddleocr\__init__.py", line 14, in <module>
    from .paddleocr import *
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddleocr\paddleocr.py", line 21, in <module>
    import paddle
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddle\__init__.py", line 31, in <module>
    from .framework import monkey_patch_variable
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddle\framework\__init__.py", line 17, in <module>
    from . import random  # noqa: F401
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddle\framework\random.py", line 17, in <module>
    from paddle import fluid
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddle\fluid\__init__.py", line 36, in <module>
    from . import framework
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddle\fluid\framework.py", line 35, in <module>
    from . import core
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddle\fluid\core.py", line 356, in <module>
    raise e
  File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddle\fluid\core.py", line 269, in <module>
    from . import libpaddle
ImportError: generic_type: type "_gpuDeviceProperties" is already registered!

When import paddleocr or ultralytics separately, both are work fine. But get error when import them together.

在Python中单独导入paddleocrultralytics时无误。但同时导入将报错。

About this issue

Most upvoted comments

In my case, helped: pip install paddlepaddle-gpu==2.4.2.post116 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html env looks like: paddlepaddle-gpu==2.4.2.post116 paddleocr==2.7.0.3 torch==2.2.0+cu118 protobuf==3.19.0

for me paddlepaddle-gpu 2.4.2 in compile by cuda11.8 with torch 2.0.1 in cuda cuda11.8 will course the same issue, but change to paddlepaddle-gpu 2.4.2 in compile by cuda11.7 is fine! https://www.paddlepaddle.org.cn/whl/windows/mkl/avx/stable.html

it seems that the problem cames out not only yolov8 ultralytics with paddleocr, but also paddlepaddle-gpu with torch. Is there any possible way to fix this.

Try to reinstall paddlepaddle-gpu to version 2.4.2. It works for me.

I was facing the same problem. It may occurs due to the PaddlePaddle dependency, which uses CUDA as default. To solve that, I tried PaddlePaddle without CUDA (CPU).

For instance: python -m pip install paddlepaddle==2.5.0 -i https://mirror.baidu.com/pypi/simple.