Import media on python gives Import Error - python

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.

Related

How to fix pip that it points to the correct python?

So i just installed python3.10 on Ubuntu 20.04 and made it default. After that tried to run a program which imports pygame and get an Error `
" ModuleNotFoundError: No module named 'pygame.base'
After a little bit of research the solution might be
pip3 uninstall pygame
and to reinstall it, but then i get that error
ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/init.py)
`which pip3 and which python3 give me 2 different directionaries
Now my question: How do i get them in the same that the pip points at the correct python ?
`
the answer exist in this stack overflow url :ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/__init__.py)
and also you can use something like that for use pip with correct python version, for instanse:
python3 -m pip install <package_name_you_want>

Tesseract-OCR / Pillow not working with Pycharm

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...

ImportError: No module named scenedetect on Linux Ubuntu

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

Failed to install scitools-iris using pip: ImportError No module named target_pkg (in pyke)

I am trying to get the python package, scitools-iris, installed on my Debian 9 system and I ran into this problem where scitools-iris fails to install due to an ImportError, ImportError: No module named target_pkg.
I am using python 2.7 and all packages are installed using pip only. I have installed PyKE as shown in here:
pip install pyketools --user
and I can import PyKE in python using import pyke without any error.
Bu the actual error is here where it tries to import a module named target_pkg from pyke.target_pkg. I tried the import statement in python,
from pyke.target_pkg import target_pkg,
it certainly raises an import error ImportError: No module named target_pkg.
How do I get around this problem and install iris in my system?
Have I installed the wrong package for PyKE?
Found out what I have been doing wrong. I actually had the wrong package installed for PyKE using pip. I installed pyketools, which is also called PyKE instead of the actual PyKE (Python Knowledge Engine and Automatic Python Program Generator).
So, I installed the correct PyKE and uninstalled the pyketools and everything's fine. Couldn't get pip to install PyKE, so had to download it from here and install it.

ImportError: No module named pytesseract

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.

Categories