Windows10下Anaconda虚拟环境pytesseract模块缺失问题求助
ModuleNotFoundError: No module named 'pytesseract' in Anaconda's venv Environment Hey Stan, let's work through why you're hitting this module not found error—even when you think you've installed pytesseract in your "venv" environment. Here are the most straightforward fixes to try:
1. Verify pytesseract is actually installed in your "venv" environment
It's easy to accidentally install packages in the wrong environment, so let's double-check:
- Via Anaconda Navigator: Open Navigator, switch to the "Environments" tab, select "venv" from the dropdown, then search for
pytesseractin the package list. If it's not there, click "Install" to add it. - Via Command Line: Open Anaconda Prompt, activate your environment first with:
Then run either of these commands to check for the package:conda activate venv
If it doesn't show up, install it directly in the activated environment:pip list | findstr pytesseract # 或者 conda list pytesseractpip install pytesseract
2. Ensure your script uses the "venv" environment's Python interpreter
A common gotcha is using the wrong Python executable to run your script. Let's confirm:
Add these lines at the top of your script and run it:
import sys print("Current Python interpreter path:", sys.executable)
The output should point to your venv environment's Python file, like C:\Users\stan\anaconda3\envs\venv\python.exe. If it shows a different path (like your base Anaconda or system Python), you'll need to adjust your IDE's interpreter settings:
- In VS Code: Press
Ctrl+Shift+P, search for "Python: Select Interpreter", then pick the "venv" environment's Python. - In PyCharm: Go to File > Settings > Project > Python Interpreter, then select "venv" from the list.
3. Don't forget the Tesseract OCR engine (critical for later!)
Even once pytesseract is installed, you'll need the actual Tesseract OCR binary to make the module work. After fixing the module error, you'll likely hit another issue if this isn't set up:
- Download and install the Tesseract OCR engine (official Windows builds are available for direct download).
- Either add the Tesseract installation folder (usually
C:\Program Files\Tesseract-OCR) to your system'sPATHenvironment variable, or specify the path directly in your script:import pytesseract from PIL import Image # Add this line to point to your Tesseract executable pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe' im = Image.open("C:\\Users\\stan\\Desktop\\sample.jpg") text = pytesseract.image_to_string(im, lang='eng') print(text)
内容的提问来源于stack exchange,提问作者Stan

