Using pytesseract on Python 2.7 and Windows XP [duplicate] - python

This question already has answers here:
f-strings giving SyntaxError?
(7 answers)
Closed last month.
I need OCR for a certain project, after searching online I decided to use python and tesseract. Right now I am trying to run the following code just to see if it works:
import pytesseract
from PIL import Image
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
print(pytesseract.image_to_string(Image.open("C:\Documents and Settings\Yerutnik\Desktop\file.bmp")))
However, I am getting the following error:
Traceback (most recent call last):
File "C:\Documents and Settings\Yerutnik\Desktop\test1.py", line 2, in <module>
import pytesseract
File "C:\Python27\lib\site-packages\pytesseract\__init__.py", line 2, in <module>
from .pytesseract import ALTONotSupported
File "C:\Python27\lib\site-packages\pytesseract\pytesseract.py", line 89
f"{tesseract_cmd} is not installed or it's not in your PATH."
^
SyntaxError: invalid syntax
I am running this on a Windows XP 32bit machine (must use this machine), Python 2.7.9, Tesseract 4.0.0 (tested working separately in cmd, and I checked that it is in PATH).

you use pytesseract for python3 (f-string is python3 feature) in python2.7 Try some old version of pytesseract.

I was able to fix this by downgrading pytesseract (as suggested by user898678) from 4.0.0 to 0.2.2, upgrading pip from 1.5.2 to 20, and installing pytesseract from web instead of using a wheel file.

Related

ImportError Pyo

I'm trying to import pyo in python3.8.8 and I'm not getting any results. When I try to run the command:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in
import pyo
File "C:\Users\andre\AppData\Roaming\Python\Python38\site-packages\pyo_init_.py", line 28, in
from .lib import analysis as analysis
File "C:\Users\andre\AppData\Roaming\Python\Python38\site-packages\pyo\lib\analysis.py", line 32, in
from ._core import *
File "C:\Users\andre\AppData\Roaming\Python\Python38\site-packages\pyo\lib_core.py", line 58, in
from .._pyo import *
ImportError: DLL load failed while importing _pyo: Impossibile trovare il modulo specificato.
How can I solve this?
I assume you are on windows. What version of pyo do you have installed? I saw that it was only version 1.0.1 that python 3.8 support was introduced. Try uninstalling pyo, then make sure you install the newest version. Also, did you install with pip? If you did, try installing from their downloadable releases on github. What code did you write that caused this error? I need to see your code.
Looks like you're using pc032 (032bit) Python. Last PyO version with pc032 (on Win) support is [PyPI]: pyo 1.0.1 (from 191127). But I didn't see the Python 3.8 .whl among files (neither for a couple of older versions).
Just out of curiosity: how did you install PyO?
In order to get things going either:
Switch to pc064 (064bit) Python
Use a (pc032) Python version that prebuilt .whl exists for
I've built v1.0.4 (latest at answer time) and placed the .whls at [GitHub]: CristiFati/Prebuilt-Binaries - (master) Prebuilt-Binaries/PyO/v1.0.4. Download and install the preferred one (check [SO]: Installing pygraphviz on Windows 10 64-bit, Python 3.6 (#CristiFati's answer) (at the end) for more details about the process)

Opencv import issue in windows 10 [duplicate]

This question already has answers here:
How do you fix "runtimeError: package fails to pass a sanity check" for numpy and pandas?
(9 answers)
Closed 2 years ago.
I have an issue with OpenCV in windows 10. Whenever I try to import OpenCV I get following error.
import cv2
** On entry to DGEBAL parameter number 3 had an illegal value
** On entry to DGEHRD parameter number 2 had an illegal value
** On entry to DORGHR DORGQR parameter number 2 had an illegal value
** On entry to DHSEQR parameter number 4 had an illegal value
Traceback (most recent call last):
File "C:\Users\Krishhnandu\AppData\Roaming\Python\Python39\site-packages\numpy\__init__.py", line 305, in <module>
_win_os_check()
File "C:\Users\Krishhnandu\AppData\Roaming\Python\Python39\site-packages\numpy\__init__.py", line 302, in _win_os_check
raise RuntimeError(msg.format(__file__)) from None
RuntimeError: The current Numpy installation ('C:\\Users\\Krishhnandu\\AppData\\Roaming\\Python\\Python39\\site-packages\\numpy\\__init__.py') fails to pass a sanity check due to a bug in the windows runtime. See this issue for more
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Krishhnandu\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\__init__.py", line 5, in <module>
from .cv2 import *
ImportError: numpy.core.multiarray failed to import
Any help will be appreciated. Thanks.
Python 3.9 is very new you should go back to 3.86 and write this in cmd
pip install opencv
First, you can find help here: How do I install opencv using pip?
Then, try the following steps:
Downgrade your current python version to python 3.8. Go there for more informations: how can I downgrade from python 3.7 to 3.6 in windows. You can also create a virtual environment with python 3.8: https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/26/python-virtual-env/
Type this command line in cmd: pip install opencv-python
Check if opencv package is installed: python -c "import cv2"
For step 2, be sure your pip version is updated.
I hope it'll help you =)

imread from scipy.misc does not work on pycharm. I can't seem to install PIL either

from scipy.misc import imread
Traceback (most recent call last):
File "<input>", line 1, in <module>
ImportError: cannot import name 'imread'
If I run the first on pycharm, I get the following message. I've came across that I need to install PIL or Pillow to work with imread. However, trying to install PIL on pycharm gives me this warning.
warning I get
+) interpreter that I'm running on pycharm is:
'/Users/jeongseohyeong/anaconda3/envs/DL/bin/python' (python 3.6)
I've also seen posts that are saying pip install pil works. However, it doesn't seem to work for me (or at least it works for my jupyter notebook which is built in '/Users/jeongseohyeong/anaconda3/bin/python'). Any help would be appreciated.
Imread has been depreciated. Either roll back to scipy 1.1 so you can use it or use another module.

Ubuntu 16.04 Python Version Management Issue

I have Python3.5 and Python3.6 installed on Ubuntu 16.04. I have installed pip for 3.6 and am using 3.6 for development. I tried to install a package (wordcloud) in 3.6 and it appeared to install correctly but I get the following error message:
Traceback (most recent call last):
File "/mnt/data/projects/CSC594/HW01/CSC594-DMARKS-HW01-WordCloud.py", line 11, in <module>
import wordcloud as wc
File "/usr/local/lib/python3.6/dist-packages/wordcloud/__init__.py", line 1, in <module>
from .wordcloud import (WordCloud, STOPWORDS, random_color_func,
File "/usr/local/lib/python3.6/dist-packages/wordcloud/wordcloud.py", line 19, in <module>
from PIL import Image
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 66, in <module>
from PIL import _imaging as core
ImportError: cannot import name '_imaging'
I am not sure what is happening but, python3 is a symbolic link to python3.5 yet when I execute the code, I am calling it in python3.6. Everything looks fine except when it calls the PIL package. PIL is actually installed in 3.6, but not 3.5.
I don't understand why it switches from:
/usr/local/lib/python3.6/dist-packages
to:
/usr/lib/python3/dist-packages
Why does this happen and how do I resolve this situation?
Trusty offers a 3.5 setup, and that won't change. It may be possible to have the two coexist in the way you suggest, but you are finding it challenging. Recommend deleting your python3.6. (Or switching to an ubuntu based on 3.6.)
Install miniconda3, and use that to provide python3.6, PIL, and friends. Very clean. You'll be glad you did.

Running the sample code in pytesseract

I am running python 2.6.6 and want to install the pytesseract package. After extraction and installation, I can call the pytesseract from the command line. However I want to run the tesseract within python. I have the following code (ocr.py):
try:
import Image
except ImportError:
from PIL import Image
import pytesseract
print(pytesseract.image_to_string(Image.open('test.png')))
print(pytesseract.image_to_string(Image.open('test-european.jpg'),lang='fra'))
When I run the code by python ocr.py, I get the following output:
Traceback (most recent call last):
File "ocr.py", line 6, in <module>
print(pytesseract.image_to_string(Image.open('test.png')))
File "/pytesseract-0.1.6/build/lib/pytesseract/pytesseract.py", line 164, in image_to_string
raise TesseractError(status, errors)
pytesseract.TesseractError: (2, 'Usage: python tesseract.py [-l language] input_file')
test.png and test-european.jpg are in the working directory. Can Someone help me running this code?
I have tried the following:
Adjusted the tesseract_cmd to 'pytesseract'
Installed tesseract-ocr
Any help is appreciated as I am trying to solve this problem for hours now.
tesseract_cmd should point to the command line program tesseract, not pytesseract.
For instance on Ubuntu you can install the program using:
sudo apt install tesseract-ocr
And then set the variable to just tesseract or /usr/bin/tesseract.

Categories