Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traceback (most recent call last): File "PPOCRLabel.py", line 80, in <module> from paddleocr import PaddleOCR, PPStructure ImportError: cannot import name 'PaddleOCR' from 'paddleocr' (unknown location) #124

Open
nissansz opened this issue Dec 16, 2024 · 2 comments

Comments

@nissansz
Copy link

Traceback (most recent call last):
File "PPOCRLabel.py", line 80, in
from paddleocr import PaddleOCR, PPStructure
ImportError: cannot import name 'PaddleOCR' from 'paddleocr' (unknown location)

@GreatV
Copy link
Collaborator

GreatV commented Dec 16, 2024

The error message you are encountering indicates that PaddleOCR and PPStructure cannot be imported from the paddleocr package. Based on the provided documentation and potential causes, here are the troubleshooting steps and solutions:


Possible Causes and Solutions

1. Incompatible or Missing PaddleOCR and PaddlePaddle Versions

  • The PaddleOCR package might not be installed correctly, or its version might be incompatible with the version of the PaddlePaddle library installed.
  • Solution:
    1. Ensure that you have installed the correct versions of the required packages. For example:
      pip install paddleocr==2.8.1 paddlepaddle==2.6.1
    2. Verify the installation using:
      pip show paddleocr
      pip show paddlepaddle
    3. Ensure that the versions match the dependencies mentioned in the installation guide of PPOCRLabel.

2. Incorrect Environment or Missing Dependencies

  • If you are using a virtual environment, ensure it is activated and properly configured.
  • Solution:
    1. Activate your environment:
      source <your_env>/bin/activate  # Linux/macOS
      <your_env>\Scripts\activate     # Windows
    2. Reinstall the required packages:
      pip install paddleocr paddlepaddle

3. Multiple Versions of OpenCV Conflicting

  • There may be a conflict between opencv-python and opencv-python-headless, which can cause errors during runtime.
  • Solution:
    1. Uninstall both OpenCV packages:
      pip uninstall opencv-python opencv-python-headless
    2. Reinstall only opencv-python-headless:
      pip install opencv-python-headless

4. Illegal Instruction Error (Hardware Incompatibility)

  • If you encounter an "Illegal instruction" error, it may indicate that your CPU does not support certain instructions required by PaddlePaddle.
  • Solution:
    1. Install a CPU-compatible version of PaddlePaddle:
      pip install paddlepaddle==2.6.1 -f https://www.paddlepaddle.org.cn/whl/cpu.html
    2. Alternatively, use Docker or a machine with compatible hardware.

5. Resolving the Specific ImportError (PaddleOCR Not Found)

  • If the ImportError persists, it might indicate a corrupted or incomplete installation of PaddleOCR.
  • Solution:
    1. Uninstall and reinstall PaddleOCR:
      pip uninstall paddleocr
      pip install paddleocr
    2. Test the import in Python:
      from paddleocr import PaddleOCR, PPStructure
      print("PaddleOCR imported successfully!")

6. OMP Error: libiomp5md.dll Already Initialized

  • This error occurs when multiple OpenMP runtimes are loaded simultaneously.
  • Solution:
    1. Set the environment variable KMP_DUPLICATE_LIB_OK=TRUE:
      export KMP_DUPLICATE_LIB_OK=TRUE  # Linux/macOS
      set KMP_DUPLICATE_LIB_OK=TRUE    # Windows
    2. This is a workaround; for a permanent fix, ensure only one OpenMP runtime is loaded by resolving library conflicts.

7. Additional Notes for Windows Users

  • If you are on Windows, ensure you install all dependencies using pip and not directly execute the script without proper setup.
  • Use the following command to launch PPOCRLabel:
    PPOCRLabel --lang ch

General Debugging Checklist

  1. Verify Python version compatibility (e.g., Python 3.8 or 3.9 is recommended).
  2. Ensure that all required dependencies (e.g., PaddleOCR, PaddlePaddle, opencv-python-headless) are installed and compatible.
  3. Check if the import works in a Python shell:
    from paddleocr import PaddleOCR, PPStructure
  4. If the error persists, consider creating a fresh environment and reinstalling everything:
    conda create -n ppocr python=3.8 -y
    conda activate ppocr
    pip install paddleocr==2.8.1 paddlepaddle==2.6.1 opencv-python-headless
    pip install PPOCRLabel
  5. Refer to the official installation guide for PPOCRLabel: PPOCRLabel Installation Guide.

Relevant Discussions

If none of the above solutions resolve the issue, please provide more details about your environment (OS, Python version, and package versions) for further assistance.


Response generated by feifei-bot | chatgpt-4o-latest

@nissansz
Copy link
Author

用paddleocr 2.6中的ppocrlabel 1.0原来是可以执行的,
后面尝试用v2.1,安装报错,想用旧的也报错了。

paddlepaddle-gpu 2.4.2 / 2.6.1/2.3.2都一样报下面错
paddleocr 2.8.1

Traceback (most recent call last):
File "L:\paddle\PaddleOCR-release-2.6\PPOCRLabel\PPOCRLabel.py", line 40, in
from paddleocr import PaddleOCR, PPStructure
File "..\paddleocr.py", line 34, in
from tools.infer import predict_system
File "..\tools\infer\predict_system.py", line 31, in
import tools.infer.utility as utility
File "..\tools\infer\utility.py", line 24, in
from paddle import inference
ImportError: cannot import name 'inference' from 'paddle' (unknown location)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants