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 'PIL' #316

Closed
liebig opened this issue Dec 15, 2020 · 16 comments
Closed

ModuleNotFoundError: No module named 'PIL' #316

liebig opened this issue Dec 15, 2020 · 16 comments

Comments

@liebig
Copy link

liebig commented Dec 15, 2020

I am trying to get pytesseract to run on a Windows 10 system but unfortunately always get the following error log:

  File "C:\Users\Marc\PycharmProjects\test\venv\lib\site-packages\pytesseract\pytesseract.py", line 27, in <module>
    from PIL import Image
ModuleNotFoundError: No module named 'PIL'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Marc\PycharmProjects\test\main.py", line 15, in <module>
    import pytesseract
  File "C:\Users\Marc\PycharmProjects\test\venv\lib\site-packages\pytesseract\__init__.py", line 2, in <module>
    from .pytesseract import ALTONotSupported
  File "C:\Users\Marc\PycharmProjects\test\venv\lib\site-packages\pytesseract\pytesseract.py", line 29, in <module>
    import Image
ModuleNotFoundError: No module named 'Image'

Process finished with exit code 1
@liebig
Copy link
Author

liebig commented Dec 15, 2020

Okay I must have messed up my installed pip packages. Created a new Python project, installed pytesseract and everything works.

@liebig liebig closed this as completed Dec 15, 2020
@sree9578
Copy link

sree9578 commented Jan 9, 2021

may i know how u closed the error i am having the same issue..
Traceback (most recent call last):
File "pytesseract.py", line 27, in
from PIL import Image
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 68, in
from PIL import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/usr/lib/python3/dist-packages/PIL/init.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "pytesseract.py", line 29, in
import Image
ModuleNotFoundError: No module named 'Image'

@bozhodimitrov
Copy link
Collaborator

Hi @sudhan-c -- it seems that your setup/virtual environment might have some kind of problem.
If you use the latest version and install it in isolated virtual environment, there should be no problems.
You can find more information how to setup clean install in the docs.

@halvomez
Copy link

hi, it's ok with version 0.3.7, but 0.3.8 crash with same error

from .pytesseract import ALTONotSupported File "/tmp/pip-install-wt3k8kh5/pytesseract/pytesseract/pytesseract.py", line 28, in <module> import Image ModuleNotFoundError: No module named 'Image'

@bozhodimitrov
Copy link
Collaborator

Can you try installing the Pillow package as a workaround? It is very strange that you have this issue for your environment, since all project tests pass.

@eddiezab
Copy link

eddiezab commented Jul 23, 2021

While this issue is closed, I've observed something interesting -- but I don't know where the breakdown is. I'm installing pytesseract (no version specified) as in a requirements.txt

python3 -m venv /tmp/envdir
. /tmp/envdir/bin/activate
pip install -r requirements.txt

Adding Pillow prior to pytesseract in the requirements.txt appears to do something, but I still get the issue as above. However, if, and only if, I explicitly run pip install Pillow (with or without it being in the requirements.txt) do I get pytesseract to install.

@VelorumS
Copy link

Steps to reproduce:

docker run -it --rm ubuntu:focal bash
apt -y update
apt -y install python3-pip
pip3 install pytesseract

Something is wrong with pytesseract package dependencies.

@liebig
Copy link
Author

liebig commented Jan 25, 2022

Okay, since this problem affects several people, I am reopening this issue.

@liebig liebig reopened this Jan 25, 2022
@bozhodimitrov
Copy link
Collaborator

Thank you very much for reporting this. I will have to investigate why it suddenly stated failing -- I suspect pip.

@bozhodimitrov
Copy link
Collaborator

bozhodimitrov commented Jan 25, 2022

@liebig @ChipmunkV Ok, so Pillow requires python 3.7 or higher, because python 3.6 is End of Life.
I updated the current CI setup for that. Can't test the docker reproduction steps right now, because I am on a restricted computer.
But you can try the following to confirm that the latest master is working:

docker run -it --rm ubuntu:focal bash
apt -y update
apt -y install python3-pip git
pip3 install -U git+https://github.com/madmaze/pytesseract.git

If this works, I can create a new release.

@VelorumS
Copy link

Same error (sorry, haven't included it the first time).

Python 3.8.10

/# pip3 install -U git+https://github.com/madmaze/pytesseract.git
Collecting git+https://github.com/madmaze/pytesseract.git
  Cloning https://github.com/madmaze/pytesseract.git to /tmp/pip-req-build-fzd_0juj
  Running command git clone -q https://github.com/madmaze/pytesseract.git /tmp/pip-req-build-fzd_0juj
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-fzd_0juj/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-fzd_0juj/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-req-build-fzd_0juj/pip-egg-info
         cwd: /tmp/pip-req-build-fzd_0juj/
    Complete output (42 lines):
    Traceback (most recent call last):
      File "/tmp/pip-req-build-fzd_0juj/pytesseract/pytesseract.py", line 26, in <module>
        from PIL import Image
    ModuleNotFoundError: No module named 'PIL'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-req-build-fzd_0juj/setup.py", line 4, in <module>
        setup()
      File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 144, in setup
        return distutils.core.setup(**attrs)
      File "/usr/lib/python3.8/distutils/core.py", line 121, in setup
        dist.parse_config_files()
      File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 701, in parse_config_files
        parse_configuration(self, self.command_options,
      File "/usr/lib/python3/dist-packages/setuptools/config.py", line 121, in parse_configuration
        meta.parse()
      File "/usr/lib/python3/dist-packages/setuptools/config.py", line 426, in parse
        section_parser_method(section_options)
      File "/usr/lib/python3/dist-packages/setuptools/config.py", line 399, in parse_section
        self[name] = value
      File "/usr/lib/python3/dist-packages/setuptools/config.py", line 184, in __setitem__
        value = parser(value)
      File "/usr/lib/python3/dist-packages/setuptools/config.py", line 515, in _parse_version
        version = self._parse_attr(value, self.package_dir)
      File "/usr/lib/python3/dist-packages/setuptools/config.py", line 349, in _parse_attr
        module = import_module(module_name)
      File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
      File "<frozen importlib._bootstrap>", line 991, in _find_and_load
      File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 848, in exec_module
      File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
      File "/tmp/pip-req-build-fzd_0juj/pytesseract/__init__.py", line 2, in <module>
        from .pytesseract import ALTONotSupported
      File "/tmp/pip-req-build-fzd_0juj/pytesseract/pytesseract.py", line 28, in <module>
        import Image
    ModuleNotFoundError: No module named 'Image'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

@bozhodimitrov
Copy link
Collaborator

bozhodimitrov commented Jan 25, 2022

Hmm, I literally just ran this thru CI testing and it worked without a problem.
From what I can see, you are not using virtualenv.
Can you test if it works inside a virtualenv:

virtualenv venv
. venv/bin/activate
pip install -U git+https://github.com/madmaze/pytesseract.git
pip list

Also, this error is from within a fresh Ubuntu focal container, right?
I wonder if this issue is related to the older pip/wheel/setuptools, because I upgrade all of them in the CI runs.

@VelorumS
Copy link

Updating either pip or setuptools solves the problem. Versions that don't work: pip 20.0.2, setuptools 45.2.0. Versions that do: pip 21.3.1, setuptools 60.5.0.

@bozhodimitrov
Copy link
Collaborator

bozhodimitrov commented Jan 25, 2022

Yeah ... It seems that Pillow depends on newer versions of those tools, for reference they even include the update step in the Pillow - Installation docs

Now I have to find which is the minimum version of those tools that allow proper installation and include them to the setup requirements ...

bozhodimitrov pushed a commit that referenced this issue Jan 25, 2022
@bozhodimitrov
Copy link
Collaborator

The new pytesseract version should fix this for now.

@YashitM
Copy link

YashitM commented Feb 19, 2022

Updating either pip or setuptools solves the problem. Versions that don't work: pip 20.0.2, setuptools 45.2.0. Versions that do: pip 21.3.1, setuptools 60.5.0.

ChipmunkV thanks for that. Updating these packages worked!

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

7 participants