V3.0rc1 Has Runtime Dep. On Setuptools

by ADMIN 39 views

Introduction

In this article, we will discuss a runtime dependency issue with the PaddlePaddle library, specifically with the V3.0rc1 version. The issue arises when the library attempts to import the setuptools module, which is not installed. This article will provide a detailed explanation of the problem, its causes, and potential solutions.

Describe the Bug

The bug is caused by a missing dependency on the setuptools module. The setuptools module is required by the PaddlePaddle library to install and manage dependencies. However, in the V3.0rc1 version, the library attempts to import setuptools at runtime, which results in a ModuleNotFoundError.

Error Message

The error message is as follows:

kreuzberg\_ocr\_paddleocr.py:242: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.venv\Lib\site-packages\paddleocr\__init__.py:14: in <module>
    from .paddleocr import (
.venv\Lib\site-packages\paddleocr\paddleocr.py:21: in <module>
    from paddle.utils import try_import
.venv\Lib\site-packages\paddle\__init__.py:38: in <module>
    from .base import core  # noqa: F401
.venv\Lib\site-packages\paddle\base\__init__.py:38: in <module>
    from . import (  # noqa: F401
.venv\Lib\site-packages\paddle\base\dataset.py:23: in <module>
    from ..utils import deprecated
.venv\Lib\site-packages\paddle\utils\__init__.py:16: in <module>
    from . import (  # noqa: F401
.venv\Lib\site-packages\paddle\utils\cpp_extension\__init__.py:15: in <module>
    from .cpp_extension import (
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    # Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    #     http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    
    # isort: skip_file
    
    from __future__ import annotations
    from typing import TYPE_CHECKING, Any
    import os
    import copy
    import concurrent
    import re
>   import setuptools
E   ModuleNotFoundError: No module named 'setuptools'

.venv\Lib\site-packages\paddle\utils\cpp_extension\cpp_extension.py:23: ModuleNotFoundError

The above exception was the direct cause of the following exception:

backend = <kreuzberg._ocr._paddleocr.PaddleBackend object at 0x000001DE22318290>
mock_find_spec = <MagicMock name='find_spec' id='205356[805](https://github.com/Goldziher/kreuzberg/actions/runs/13844252481/job/38738917361?pr=27#step:11:806)0640'>

    @pytest.mark.anyio
    @pytest.mark.skipif(sys.version_info > (3, 12), reason="paddle does not support python 3.13 yet")
    async def test_init_paddle_ocr_initialization_error(backend: PaddleBackend, mock_find_spec: Mock) -> None:
        """Test handling initialization errors."""
    
        PaddleBackend._paddle_ocr = None
    
        async def mock_run_sync_error(*args: Any, **_: Any) -> None:
            if args and args[0].__name__ == "PaddleOCR":
                raise Exception("Initialization error")
    
        with patch("kreuzberg._ocr._paddleocr.run_sync", side_effect=mock_run_sync_error):
            with pytest.raises(OCRError) as excinfo:
>               await backend._init_paddle_ocr()

tests\ocr\paddleocr_test.py:234: 

Causes of the Bug

The bug is caused by the following reasons:

  1. Missing Dependency: The setuptools module is not installed, which is required by the PaddlePaddle library.
  2. Runtime Import: The PaddlePaddle library attempts to import setuptools at runtime, which results in a ModuleNotFoundError.

Solutions to the Bug

To fix the bug, you can try the following solutions:

  1. Install Setuptools: Install the setuptools module using pip: pip install setuptools.
  2. Update PaddlePaddle: Update the PaddlePaddle library to the latest version, which may fix the issue.
  3. Modify the Code: Modify the code to avoid importing setuptools at runtime. Instead, import it during installation or setup.

Conclusion

Q: What is the issue with the V3.0rc1 version of the PaddlePaddle library?

A: The V3.0rc1 version of the PaddlePaddle library has a runtime dependency on the setuptools module. This means that the library attempts to import setuptools at runtime, which results in a ModuleNotFoundError if setuptools is not installed.

Q: Why is setuptools required by the PaddlePaddle library?

A: Setuptools is required by the PaddlePaddle library to install and manage dependencies. It is used to install and configure the library's dependencies, such as the cpp_extension module.

Q: How can I fix the issue with the V3.0rc1 version of the PaddlePaddle library?

A: To fix the issue, you can try the following solutions:

  1. Install Setuptools: Install the setuptools module using pip: pip install setuptools.
  2. Update PaddlePaddle: Update the PaddlePaddle library to the latest version, which may fix the issue.
  3. Modify the Code: Modify the code to avoid importing setuptools at runtime. Instead, import it during installation or setup.

Q: What are the consequences of not installing setuptools?

A: If setuptools is not installed, the PaddlePaddle library will raise a ModuleNotFoundError when attempting to import it at runtime. This will prevent the library from functioning correctly and may cause errors or crashes.

Q: Can I use an older version of the PaddlePaddle library to avoid the issue?

A: It is not recommended to use an older version of the PaddlePaddle library to avoid the issue. Older versions may have other issues or bugs that are not fixed in the latest version. Instead, it is recommended to update to the latest version and install setuptools to fix the issue.

Q: How can I prevent this issue from occurring in the future?

A: To prevent this issue from occurring in the future, you can:

  1. Install setuptools: Install setuptools as a dependency of your project to ensure that it is always available.
  2. Use a virtual environment: Use a virtual environment to isolate your project's dependencies and prevent conflicts with other projects.
  3. Update the PaddlePaddle library regularly: Regularly update the PaddlePaddle library to ensure that you have the latest version and any fixes for issues like this.

Q: Where can I find more information about the PaddlePaddle library and its dependencies?

A: You can find more information about the PaddlePaddle library and its dependencies on the official PaddlePaddle website, as well as on GitHub and other documentation resources.