No module named pil python что делать

от admin

[SOLVED] Python No Module Named Pil

Python Image Library or PIL is an image processing module developed for Python. It provides image processing tools that help in creating, editing, and exporting image files. However, the PIL project was abandoned in 2011. To continue providing support for the latest Python versions, the Pillow module forked the PIL module. The Pillow module eventually replaced PIL and became the go-to image processing library for Python.

The Python interpreter may not detect specific modules when imported. Therefore, upon execution, Python will return the ModuleNotFoundError: No module named ‘pil’ exception and exits the program.

For example, let’s say we’re importing a package called “run”. We would do so by using the import statement followed by the package name ; run. Since there is no module called “run”, this error is shown.

No module named "run"

Causes & Solutions For No Module Named Pil

There are multiple reasons why this exception may be raised. Let’s look at the following instances.

Package Not Installed Properly

This is probably the most typical reason for this exception. Some libraries may not be part of the Python Standard Library. Therefore they require additional installation steps before we can use them.

In specific IDEs (e.g., spyder), make sure your module are all installed in a single folder. PIP installer may install your package in one place, whereas the IDE expects the module in another directory. Make sure to save all external dependencies in one place.

It is vital to ensure that the correct installation commands for provided to install Pillow.

Multiple Python Versions Installed

Installing multiple versions of Python can result in multiple library folders for each version. Therefore, ensure the library is present in the correct version of Python.

Here’s how we can find the installation location for your version of Python

Open up the Python command terminal

Python application 3.10

Type the following lines of commands

Output

Python location

So the location would be: ‘C:\Users\Admin\AppData\Local\Programs\Python\Python310’

Incorrect Package Name

Certain packages have import statements that are different from their actual names. One notable example is a web scraping library called BeautifulSoup . The common user may attempt to import the module by calling import BeautifulSoup .

However, this is incorrect. You must go through the documents of each module and figure out the correct import command to avoid confusion. Furthermore, the correct implementation for the said example would be: import bs4

Importing Files

Another reason for the error to arise is importing Python files incorrectly. For example, let’s assume we’re importing the file “program.py”. To import this, we run “ import program ” excluding the .py extension. It is also essential to ensure that the file is present in the working directory. If failed to do so, the following error will appear:

No module named program

Another rule to remember is that do not use names of pre-existing packages as your Python file name i.e pil.py . If done otherwise, the Python interpreter will consider pandas as your Python file rather than the pil package itself. This will cause problems when working with your file and the package.

Automate Browser with Selenium Python

Python No Module Named Pil Visual Studio Code

Users tend to face an issue with the module in VSCode. Upon importing, the program may run perfectly, but under the problems tab, this may appear:

This error is caused due to the fact that VS Code isn’t running the same Python interpreter between the two or more versions. Modules are installed on one of the Python versions you have. Therefore, we must determine the path to the Python executable. Refer to the following command

This will show us the location in which Python is installed. If you run the same command on VS Code, it will show a different location. In order to have the versions in the same location, we must install the Python interpreter that is being used by VS Code. Type this in your terminal

No Module Named pil.imagetk

For Versions Below Python 3

This is due to the fact that Python is installed in a different location than the standard one. This can be fixed by re-installing Python to the standard location or by appending the location to sys.path .

For Versions Above Python 3

Python 3 and above imagetk comes under the Pillow module. Therefore, in order to import, run the following command.

No Module Named PIL (macOS)

PIL is a deprecated project, and no further support is provided. However, the Pillow project forked PIL to provide support for the latest Python versions. For macOS machines, the following command needs to be entered.

In some instances, the following error may appear.

An easy solution to this problem is to make sure PIP is upgraded to the latest versions. PIP makes sure all your packages are unzipped and loaded into Python, ready to use. Therefore, it is vital to upgrade PIP in order to install the latest versions of modules. You can upgrade PIP using the following command in macOS

No Module Named PIL (Ubuntu)

In some versions of PIL in Ubuntu, it may come under the name imaging. Therefore in order to install Pillow in Ubuntu, run the following command.

No Module Named PIL (Raspberry Pi)

Upon installing the module on your Pi 0, you may be presented with the following error

Despite the successful installation, you may be presented with No Module Named Pil error upon running your Python file.

This may be due to the fact that the version of PIL and Python do not match. Make sure your Pi has the correct version of Python installed, and it makes sure the PIL installation matches your Python version.

Pil.exiftags file missing from the Module

Upon installation, the . exiftags function may not work. This may be due to the fact that other versions of the same module may cause the file to be deleted or overwritten.

Deleting all module versions and only saving the latest one can fix this issue.

Support for Python Image Library has been discontinued. Therefore, for the module to work on newer Python versions, the Pillow project forked the existing PIL project. All functionalities from PIL are present in Pillow as well.

Add RUN apk add zlib-dev jpeg-dev gcc musl-dev within your docker file and add Pillow within the requirements.txt file

Pillow provides image processing capabilities for Python. It has multiple file format support and powerful image processing abilities.

Conclusion

We’ve gone through various causes for Python No Module Named Pil exception. Make sure to keep these reasons in mind, as most “No Module Named” errors have similar reasons.

How to Solve Python ModuleNotFoundError: no module named ‘pil’

ModuleNotFoundError: no module named ‘pil’

What is PIL?

PIL stands for Python Imaging Library and is a library for image processing. We often use PIL together with other image processing libraries like OpenCV.

What is the Difference Between PIL and Pillow?

Pillow is a fork of the PIL library; in other words, it is built on top of PIL. PIL support ended in 2011; therefore, it is no longer up-to-date nor secure to use. If you want to use the image processing capabilities that PIL provided, you should use the Pillow library.

The simplest way to install Pillow is to use the package manager for Python called pip. The following installation instructions are for the major Python version 3.

How to Install Pillow on Windows Operating System

First, you need to download and install Python on your PC. Ensure you select the install launcher for all users and Add Python to PATH checkboxes. The latter ensures the interpreter is in the execution path. Pip is automatically on Windows for Python versions 2.7.9+ and 3.4+.

You can check your Python version with the following command:

You can install pip on Windows by downloading the installation package, opening the command line and launching the installer. You can install pip via the CMD prompt by running the following command.

You may need to run the command prompt as administrator. Check whether the installation has been successful by typing.

Pillow installation on Windows Using pip

To install Pillow, run the following command from the command prompt.

How to Install Pillow on Mac Operating System using pip

Open a terminal by pressing command (⌘) + Space Bar to open the Spotlight search. Type in terminal and press enter. To get pip, first ensure you have installed Python3:

Download pip by running the following curl command:

The curl command allows you to specify a direct download link. Using the -o option sets the name of the downloaded file.

Install pip by running:

From the terminal, use pip3 to install Pillow:

How to Install Pillow on Linux Operating Systems

All major Linux distributions have Python installed by default. However, you will need to install pip. You can install pip from the terminal, but the installation instructions depend on the Linux distribution you are using. You will need root privileges to install pip. Open a terminal and use the commands relevant to your Linux distribution to install pip.

Installing pip for Ubuntu, Debian, and Linux Mint
Installing pip for CentOS 8 (and newer), Fedora, and Red Hat
Installing pip for CentOS 6 and 7, and older versions of Red Hat
Installing pip for Arch Linux and Manjaro
Installing pip for OpenSUSE
Pilow installation on Linux with Pip

Once you have installed pip, you can install Pillow using:

Installing Pillow Using Anaconda

First, to create a conda environment to install PIL.

Читать:
Что делать если поймал вирус в компьютере

Then activate the pillow container. You will see “pillow” in parentheses next to the command line prompt.

Now you’re ready to install Pillow using conda.

Anaconda is a distribution of Python and R for scientific computing and data science. You can install Anaconda by going to the installation instructions. Once you have installed Anaconda and created your conda environment, you can install Pillow using one of the following commands:

Check Pillow Version

Once you have successfully installed Pillow, you can use two methods to check the version of Pillow. First, you can use pip show from your terminal. Remember that the name of the Pillow package is pillow , not PIL.

Second, within your python program, you can import pillow and then reference the __version__ attribute:

Note that you need to import PIL, though you installed pillow. Pillow is simply a repackaged, updated version of PIL.

If you used conda to install Pillow, you could check the version using the following command:

Summary

Congratulations on reading to the end of this tutorial. The modulenotfounderror occurs if you misspell the module name, incorrectly point to the module path or do not have the module installed in your Python environment. If you do not have the module installed in your Python environment, you can use pip to install the package. However, you must ensure you have pip installed on your system. You can also install Anaconda on your system and use the conda install command to install Pillow. Remember to use Pillow, and you have to use the import statement: import PIL

Go to the online courses page on Python to learn more about Python for data science and machine learning.

No module named PIL #3851

The text was updated successfully, but these errors were encountered:

it is installing for the right version,
i didnt have import PIL but i just tried and same error,

Since you have ‘venv’ in your path, I presume that the answer to this question involves the fact that you’re using a virtual environment. https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/ might prove useful.

Otherwise, a quick solution might be —

  • If you run pip show Pillow , the location of the Pillow package will be shown.
  • If you run python -m site , one of paths shown will be the location of your Python install’s site-packages directory.
  • If you copy Pillow from the pip location to the Python site-packages directory, you should be able to import Pillow after that.

Here’s the thing:
Pip location : c:\users\cs-admin\appdata\local\programs\python\python36\lib\site-packages

Install location : ‘C:\Users\cs-admin\AppData\Local\Programs\Python\Python36\lib\site-packages’,

change PIL with pil
It works for me

change PIL with pil
It works for me

simple solution, but it was really pain. Thanks

sorry to comment on this old question but I already tried this and this was working but now when I do «import PIL» it says «no module named PIL» but when I do «import pil» it gave the same error «no module named PIL» in capital letters.

change PIL with pil
It works for me

it doesnt for me.
literally all i want to do is show an image in python.
i have been trying for hours.
someone please help me.

Edit: incase this matters, i went to the file location of where pip said it installed pillow, but couldnt find anything to do with pillow.

Edit 2: actually i found it, it was installed in C: instead of C:\Users<user>\AppData\Local\Programs\Python
thats definitely a bad thing, right? if anyone could please help me i would be so grateful.

Edit 3: ok, now ive fixed it, but its saying «cannot import name ‘_imaging’ from ‘PIL’
that’s weird, as i told it to import «Image», not «_imaging». does anyone have a solution?

I found a solution that worked for me :
First I uninstalled the old version of pil located for me in %localappdata%\Programs\Python\Python37-32\Lib\site-packages\ and removed the pil folder
Then I updated Pillow using pip install Pillow==7.1.2 and adding the version was necessary because otherwise, it will install the latest version of Pillow that can work for every dependency
And then doing from PIL import Image worked

change PIL with pil
It works for me

When I exited my virtual environment it seemed to work

i hope this helps but i belive your python is 3 version which means for you to execute the script you made instead of typing «python script.py» , you should instead use «python3 script.py» and that because you must have 2 versions of python and the pillow path in the python 3 part while the execution was made on python2 i hope this help because that what worked for me

Screenshot_7

oh em gi
i have the same problem and nothing seems to work 🙁

For me it was a python version problem. Fixed it by using pip3 install Pillow and then starting the script with python3 script.py

For me it was a python version problem. Fixed it by using pip3 install Pillow and then starting the script with python3 script.py

Yep, that’s why the installation instructions recommend python3 -m pip install —upgrade pillow

Exactly, I tried everything on the internet, nothing seems to work

Thankfully, it’s now working. What I did was, I deleted pip from the location where it was saved, which in my case was:
C:\Users<My folder name>\AppData\Local\Microsoft\WindowsApps. Then I installed it again using this website: https://datatofish.com/upgrade-pip/

This time, I installed it in (I changed the location with the help of that website):
C:\Users<Folder name>\AppData\Local\Programs\Python\Python38-32\Scripts

Then I used pip install pillow and installed it in the same place, Python Scripts area given above. Uninstall it using pip uninstall pillow if it wasn’t already.

Then import PIL in Python and it’ll work!

Thankfully, it’s now working. What I did was, I deleted pip from the location where it was saved, which in my case was:
C:\Users\AppData\Local\Microsoft\WindowsApps. Then I installed it again using this website: https://datatofish.com/upgrade-pip/

This time, I installed it in (I changed the location with the help of that website):
C:\Users\AppData\Local\Programs\Python\Python38-32\Scripts

Then I used pip install pillow and installed it in the same place, Python Scripts area given above. Uninstall it using pip uninstall pillow if it wasn’t already.

Then import PIL in Python and it’ll work!

Could you please write down your approach step by step?

I’d like to try this suggestion but I am not sure if I can follow the directions correctly now.

Thankfully, it’s now working. What I did was, I deleted pip from the location where it was saved, which in my case was:
C:\Users\AppData\Local\Microsoft\WindowsApps. Then I installed it again using this website: https://datatofish.com/upgrade-pip/
This time, I installed it in (I changed the location with the help of that website):
C:\Users\AppData\Local\Programs\Python\Python38-32\Scripts
Then I used pip install pillow and installed it in the same place, Python Scripts area given above. Uninstall it using pip uninstall pillow if it wasn’t already.
Then import PIL in Python and it’ll work!

Could you please write down your approach step by step?

I’d like to try this suggestion but I am not sure if I can follow the directions correctly now.

When I installed pillow from command prompt, I just entered the command pip install pillow and not specified any location, so it installed pillow to the default location, which in my case was C:\Users\<User Name>\AppData\Local\Microsoft\WindowsApps (I’m pretty sure it’s the same in yours too).

So I went there ( C:\Users\<User Name>\AppData\Local\Microsoft\WindowsApps ) and manually deleted pip from there the usual way like we delete files. Then, I installed pip using this website: https://datatofish.com/upgrade-pip/ to this location: C:\Users\<User name>\AppData\Local\Programs\Python\Python38-32\Scripts .

After I installed pip, using the same cd\ and cd (Given in the site), I changed the location to C:\Users\<User name>\AppData\Local\Programs\Python\Python38-32\Scripts and wrote pip install pillow . In the previous answer, I’ve written use pip uninstall pillow if it is already installed, but I guess it’ll uninstall itself if the whole pip is deleted. Still, to be on the safer side, you can use pip uninstall pillow first before installing.

Python ImportError: No module named PIL Solution

If you use the Python image library and import PIL, you might get ImportError: No module named PIL while running the project. It happens due to the depreciation of the PIL library. Instead, it would help if you install and use its successor pillow library to resolve the issue.

What is ImportError: No module named PIL?

If you use Python version 3 and try to install and use the PIL library, you will get the ImportError: No module named PIL while importing it, as shown below.

PIL is the Python Imaging Library developed by Fredrik Lundh and Contributors. Currently, PIL is depreciated, and Pillow is the friendly PIL fork by Alex Clark and Contributors. As of 2019, Pillow development is supported by Tidelift.

How to fix ImportError: No module named PIL?

If you are using Python version 3, the best way to resolve this is by uninstalling the existing PIL package and performing a clean installation of the Pillow package, as shown below.

Step 1: Uninstall the PIL package.

Step 2: Install the Pillow using pip as shown below on different operating systems.

On Windows

On Linux

On OSX

Note: Sometimes, while importing matplotlib in your Jupyter notebook, you might face this issue and doing a standard install of Pillow may not work out. You could do a force install of Pillow, as shown below, to resolve the error.

Step 3: The most crucial class in the Python Imaging Library is the Image class, and you can import this as shown below.

If successful, this function returns an Image object. You can now use instance attributes to examine the file contents:

Note: If you use Python version 2.7, you need to install image and Pillow packages to resolve the issue.

Похожие статьи