I have installed Tesseract-OCR using the provided installer and added it to the path. I have also installed Pillow using pip through CMD. But when I attempt to import them into pycharm it says that the modules do not exist.
When I type 'tesseract' in CMD, it outputs the correct information, so I think I must be missing a step somewhere.
I am attempting to import them using the Following:
from PIL import Image
import pytesseract
Please help...
Related
when I run the following
from tkinter import *
from PIL import ImageTk, Image
root.mainloop()
I got
Traceback (most recent call last):
File "image_viewer.py", line 2, in <module>
from PIL import ImageTk, Image
ImportError: No module named PIL
but I already install Pillow and everything is fine.
Use Pillow which is the "new" or the replacement of PIL, but has the same-named modules to preserve compatibility:
pip install pillow
Also, as suggested in the comments, maybe you are just using the wrong python binary, try to check if you're in/out of a virtual environment or check differences between python vs python3 vs python2 on your system:
python -m pip list
python2 -m pip list
python3 -m pip list
If you are sure that you already installed pillow use this command pip install pillow --upgrade, then you can use the command pip freeze to list all modules that have been installed.
The problem is that you are not running the same python interpreter. In addition, the problem could arise from this fact that python cannot find the path to the OpenCV.
You first need to find the path to the OpenCV installed on your OS.
First, open a python script and run this:
import cv2
PATH = cv2.__file__
print(PATH)
This will print the PATH to the OpenCV installed on your OS.
Then, add the following two lines to the top of your main script (before calling tkinter and PIL):
import sys
sys.path.append('PATH')
from tkinter import *
from PIL import ImageTk, Image
root.mainloop()
Alternative Solution:
The problem could be that you are not running the same python interpreter.
You first need to find the path to the python executable that is interpreting your python scripts.
Open a python script and run this:
import sys
PATH = sys.executable
print(PATH)
This will print the path to the python executable that is interpreting your python scripts.
Now, you can install pillow in the found path as follows:
PATH -m pip install pillow
I'm trying to use pyscenedetect library on python for videos but I get this error when using the python interface and when I use the command line interface I get the error "ModuleNotFoundError: No module named 'cv2'"
even though I believe I installed both correctly according to the documentations.
I have trying to look for different ways to import opencv for the second error but to no avail. As for the first error i can't find any answers to my problem.
import cv2
import numpy as numpy
import os
import scenedetect
from scenedetect.video_manager import VideoManager
from scenedetect.scene_manager import SceneManager
from scenedetect.frame_timecode import FrameTimecode
from scenedetect.stats_manager import StatsManager
from scenedetect.detectors import ContentDetector
If you have pip you can try
pip install opencv-python
If you have anaconoda, you can try
conda install -c conda-forge opencv
it's probable that you installed it on a different python installation in your PC.
To know where your python installation is you can launch python and:
import sys
sys.path
To get the list of everything you have installed you can:
pip freeze > installed_modules.txt
Try only running
import cv2
So that you can test it
I found the problem. As Ivan was pointing out, the problem was with openCV.
I used the following command:
sudo apt install python3-opencv
I currently am running Python 3.5 and using Spyder from Anaconda as my IDE. I am running this on a Windows machine.
When I write import cv3 at the top of my code, it returns the error ImportError: No module named 'cv3'
I attempted to install opencv3 again with the command conda install -c https://conda.binstar.org/menpo opencv3 in the Command Prompt. It is apparently already installed because it returned
Fetching package metabase...............
Solving package specifications: .
# All requested packages already installed.
# packages in environment at C:\Users\Joey\Anaconda3:
# opencv3 3.1.0 py35_0 https://conda.binstar.org/menpo
Am I importing cv3 wrong? How do I fix this error?
Update: Tried import cv3 instead of import cv2 but got the following error: ImportError: cannot import name 'cv2'. The wording on the two errors is different, so python must acknowledge there is opencv installed but it does not work for some reason. Any ideas?
Ironically enough, the module is still called cv2 because it doesn't represent the version of opencv but the actual C++ API underneath which is, to be contrasted from the C API, named - cv2... So try with: import cv2
Problem solved by using command pip uninstall opencv-python in the Command Prompt.
I have attempted several installations of opencv and I suppose one may have downloaded badly and Anaconda was attempting to read that one. I looked into the build of some of the other installations I attempted and some were for Python 2.7. Maybe that contributed to the error.
Thankfully, this worked. Now import cv2 works perfectly. No errors.
I used the same approach to install the package. However, I could not import the library using the name opencv3. I had to use cv2 which worked for me.
Elaborating on #zwer's answer, check the version of OpenCV after import cv2.
>>> cv2.__version__
'3.1.0'
So basically it's calling the OpenCV3 library.
Here is the piece of code:
from PIL import Image
from pygraphics import media
toy_story = media.Movie()
I get the following error:
ImportError: No module named 'Image'
If I comment out the from pygraphics import media line it works. But then I need the media package. what's going on here. I have installed all the required packages by doing pip install <module name>. If I comment out from PIL import Image I still get the same error. What is going on here?. I have looked at other similar questions on here. But none of them answer this question.
TL;DR import media doesn't work. It gives the error ImportError: No module named 'Image'. But I have already installed Image via PIL. Help!!
I am on a mac and using python 3.5.1.
In your terminal, run python3 -m pip install <module_name>. pip has likely installed the module for python2, which you can verify by running help("modules") in python2 and python3. Running pip -V will also tell you which version of Python pip is installing modules for.
I was following this guide https://realpython.com/blog/python/setting-up-a-simple-ocr-server/ and got to the part where I run cli.py python flask_server/cli.py but I get
python cli.py
Traceback (most recent call last):
File "cli.py", line 3, in <module>
import pytesseract
ImportError: No module named pytesseract
How can I solve this ?
I also saw that I have multiple versions of python. I have linux-kali installed with the latest updates.
Something else: he runs the command like python flask_server/cli.py- where is that flask_server located ? I simply ran it like python cli.py(I was in some directory in which I created the file).
Python import errors usually boils down to one of those three cases (whether is is modules you developed; or modules distributed as packages):
You did no install the required package. Googling pytesseracttells me its an OCR that is distributed and installable using Python package manager tool pip by running pip install pytesseract in your favorite shell.
You did install the package, but is is not in your python path.
(Less often) You did install the package, and it is in your python path, but you used a name already in user by Python, and the two are conflicting.
In your case, I strongly think this is the first one. Case 2. and 3. can be assessed by calling python -v your_script.pyas described in this answer.
I had a similar error. So I hope to help people with this kind of problems.
In my case,
I tried to run python code using pytesseract lib on Raspberry pi 3.
$ pip install pillow
$ pip install pytesseract
(followed by https://www.pyimagesearch.com/2017/07/10/using-tesseract-ocr-python/)
and then, I made an example.py to test.
example.py
try:
import Image
except ImportError:
from PIL import Image
from pytesseract import *
print(pytesseract.image_to_string(Image.open('YOUR_IMAGE_PATH')))
and then, when I run this code, I got below error like you.
ImportError: No module named pytesseract
After I saw the #Bertrand Caron's answer, I found a solution.
My problem was package library path.
I also have multiple versions of python, 2.7 and 3.5, like a writer.
When I run command $python --version on linux, the result is Python 2.7.13.
In my case, when I installed a pytesseract package,
it was stored in "/usr/local/lib/python3.5/dist-packages/pytesseract".
And When I ran $python -v example.py, I found the referenced packages path hadn't been same with upper pytesseract package directory.
cf.
installed pytesseract path : /usr/local/lib/python3.5/dist-packages/pytesseract
actual referenced lib path, when running : /usr/lib/python2.7/dist-packages/
So, I copied pytesseract, located in "/usr/local/lib/python3.5/dist-packages/pytesseract" to "/usr/lib/python2.7/dist-packages/"
Then, Solved!
In my case, I was running it in Jupyter so I used this command,
! pip install --user pytesseract
But I forgot to restart the kernal. You need to restart the kernal after installing the pakcage
I had the same error. My solution is
$ pip3 install pytesseract
since I have python 2 and python 3 installed together.