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

ModuleNotFoundError: No module named 'torch.backends' with easyocr and Python 3.13 (Windows 11) - Exhaustive Troubleshooting, Still Stuck! #1375

Open
Mohammadkinggh opened this issue Feb 15, 2025 · 0 comments

Comments

@Mohammadkinggh
Copy link

Hello guys,

I'm pulling my hair out trying to get easyocr working with Python 3.13 on Windows 11. I keep getting the dreaded ModuleNotFoundError: No module named 'torch.backends' error, even though everything seems to be installed correctly. I've spent days on this, and I'm at a complete loss.

The Core Problem:

I'm trying to use easyocr, which depends on PyTorch (torch). My script fails with the ModuleNotFoundError, meaning easyocr can't find the torch.backends module. This happens despite pip showing all required packages (easyocr, torch, torchvision) as installed. The problem seems specific to my main Python 3.13 installation.

What I've Tried (A LOT):

I've tried a ton of things, so I'll try to keep this organized:

  1. Initial Tesseract Issues (Abandoned): I originally tried pytesseract, but Tesseract was a nightmare to configure. I switched to easyocr to avoid that mess.

  2. easyocr Installation: I used pip install easyocr. This should have installed all dependencies, including PyTorch.

  3. PyTorch Shenanigans:

    • Tried pip install torch (CPU version). pip says it's already installed.
    • Checked import torch; print(torch.__version__) - PyTorch seems to be installed.
    • Even tried specific, compatible versions of torch, torchvision, and easyocr based on Stack Overflow suggestions. No luck.
  4. Environment Variable Voodoo:

    • Verified TESSDATA_PREFIX is irrelevant (since I'm not using Tesseract anymore).
    • Double, triple, quadruple-checked my PATH environment variable. It should include:
      • C:\Users\Mohammad\AppData\Local\Programs\Python\Python313
      • C:\Users\Mohammad\AppData\Local\Programs\Python\Python313\Scripts
    • Made sure those paths are at the top of the PATH list (or at least before any other Python installations).
    • IMPORTANT NOTE: where python returns nothing, which is a huge red flag!
  5. Interpreter Checks:

    • Used the full path to my Python 3.13 executable: & "C:\Users\Mohammad\AppData\Local\Programs\Python\Python313\python.exe" "F:\..."
    • This lets the script start, but the ModuleNotFoundError still happens.
  6. site-packages Inspection:

    • Looked in C:\Users\Mohammad\AppData\Local\Programs\Python\Python313\Lib\site-packages for conflicting torch installations or weird files. Didn't find anything obvious.
  7. Reinstalling Everything: Uninstalling and reinstalling easyocr and torch multiple times. No change.

What I HAVEN'T Done (Yet - and this is probably crucial):

  • Portable Python Test: I haven't yet tested with a portable Python installation to isolate whether the issue is system-wide or specific to my main Python 3.13 install. This is probably my next step.
  • Check module __file__ attributes: I haven't definitively figured out which specific torch module Python is actually trying to load. I should run this inside the Python 3.13 interpreter (using the full path):
```python
import easyocr
print(easyocr.__file__)
import torch
print(torch.__file__)
```

Summary of the Situation:

  • ModuleNotFoundError persists, no matter what I try.
  • Python interpreter is reachable (with the full path).
  • where python returns nothing - major PATH issue.
  • Haven't ruled out conflicting packages or a corrupted PyTorch installation within my main Python 3.13.
  • haven't ruled out that it is a system wide problem

I'm really hoping someone has seen this before or has some fresh ideas. I'm desperate! Any help would be massively appreciated. I feel like I'm missing something obvious.

TL;DR: ModuleNotFoundError: No module named 'torch.backends' with easyocr and Python 3.13 on Windows 11, despite extensive troubleshooting (PATH, versions, reinstalls, etc.). Haven't done a portable Python test or checked __file__ attributes yet. Help!

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

1 participant