0

I am currently trying to do some image analysis work but cannot seem to get PIL installed. When I run my code (any code that has the from PIL import Image line) it gives me the error of No module named "PIL".

I tried to install PIL using pip install PIL and it gives me the error: ERROR: Could not find a version that satisfies the requirement PIL and ERROR: No matching distribution found for PIL.

The same error is displayed when I try to install the package using PyCharms project interpreter window. I have already tried running the line: pip install Pillow and it just says that I already have it installed. Can someone help me? Is there something I'm missing?

martineau
  • 119,623
  • 25
  • 170
  • 301
Angel Ortiz
  • 72
  • 13
  • How are you running the script that contains the `from PIL import Image` line? If it's from within PyCharms, the problem may be due to the IDE not knowing it's installed and you will need to do something to configure it. – martineau Jan 06 '21 at 21:41
  • 1
    The command to install pip is: >pip install pillow – Alfredo Maussa Jan 06 '21 at 22:02
  • @martineau I have ran both the pip install PIL in the IDEA and in the cmd and still get the same output. I don't think that the problem is with the IDEA since I get the same error with both the cmd and PyCharm. And with regard to where have I ran the script, I have ran it in the cmd succesfully but not in the IDEA. How can I fix the IDEA in that case? – Angel Ortiz Jan 07 '21 at 00:21
  • @AlfredoMaussa thanks for the recommendation but as I stated in the question, I already tried that. In the comment above martineau explains that it may be the IDEA. Any idea on how to fix that? – Angel Ortiz Jan 07 '21 at 00:23
  • If you're using Windows, you can download a pre-built Python "whl" file for the latest version of Pillow from [here](https://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow) (make sure to get the right version). Afterwards use `pip` to install it from that file — see [How do I install a Python package with a .whl file?](https://stackoverflow.com/questions/27885397/how-do-i-install-a-python-package-with-a-whl-file/27909082#27909082). If `pip` refuses to install it because it's already there, uninstall the module first with `pip uninstall Pillow`. – martineau Jan 07 '21 at 00:39
  • I had a similar problem, with `No module named "PIL"` back then i fixed it with: `from pil import Image`, changing `PIL` to `pil`. could you try that? – Alfredo Maussa Jan 07 '21 at 02:45
  • @martineau I just tried that and successfully installed it using the instructions you gave me. Then I restarted PyCharm and it still had the same error. (P.S. Sorry, I meant to write IDE) – Angel Ortiz Jan 07 '21 at 19:49
  • @AlfredoMaussa , the problem is that I am not directly using the library PIL. I am importing pytesseract which in turns uses the line "from PIL import Image". The same problem is being caused with another library I am using called easyocr. – Angel Ortiz Jan 07 '21 at 19:51
  • If you don't use PyCharm and instead just start the Python interpreter from the command-line (by entering `python`) and then after it starts type the command `from PIL import Image` into it, does it give you the same error? – martineau Jan 07 '21 at 19:59
  • @Alfredo Maussa: I don't know what your problem was, but the correct spelling is uppercase `PIL`. – martineau Jan 07 '21 at 20:01
  • @martineau I just ran that line in the command-line and it did NOT produce the error. It ran just fine. I think I am starting to think that the error ir being caused by the PyCharm IDE. Maybe somewhere in the virtual environment. I don't know. – Angel Ortiz Jan 09 '21 at 22:15
  • Angel: That means it's installed. If you're using a virtual environment, you will need to get Pillow/PIL installed into that. You should have mentioned that you were using one from the very beginning. – martineau Jan 09 '21 at 23:35
  • @martineau I said I was using PyCharm and PyCharm uses a virtual environment by default. Anyway, the virtual environment gives an error when in the PyCharm terminal I write "python" and then "from PIL import Image". What can I do then to download it to the virtual environment? As I said earlier, even when using the project interpreter and attempting to add the PIL package I am not able to get it downloaded. It shows the same error as I posted above. – Angel Ortiz Jan 11 '21 at 00:13
  • I'm not familiar with PyCharm, so wouldn't know it uses virtual environments by default, nor how to install things into them. It a common issue with IDEs. There's surely some way to do it, or it won't be of much use to anyone — and there are likely questions here about that specific topic. Good luck. – martineau Jan 11 '21 at 00:20
  • This PyCharm documentation might be helpful: [Install, uninstall, and upgrade packages](https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html) – martineau Jan 11 '21 at 12:09

0 Answers0