- ModuleNotFoundError: No module named ‘PIL’ #36
- Comments
- NewEricWang commented Jun 12, 2018
- yliess86 commented Jun 12, 2018 •
- python3—no module named PIL #3825
- Comments
- ljh0279 commented Nov 22, 2017
- Gosicfly commented Nov 22, 2017
- ljh0279 commented Nov 22, 2017
- zou3519 commented Nov 22, 2017
- ljh0279 commented Nov 22, 2017
- KingCyrus commented Nov 2, 2019
- Taulant8 commented Nov 19, 2019
- lukhuak commented Feb 23, 2020
- indolentdeveloper commented May 7, 2020
- uaahacker commented Nov 21, 2020
- Ali-Kamel commented Jan 10, 2021
- No Module named PIL
- 7 Answers 7
- Python — ModuleNotFoundError: No module named
- 5 Answers 5
- Ошибка «ModuleNotFoundError: No module named ‘setuptools’» (РЕШЕНО)
- Как переустановить setuptools
ModuleNotFoundError: No module named ‘PIL’ #36
Comments
NewEricWang commented Jun 12, 2018
Hi, When I run command «/usr/bin/python train.py —output_directory=works —log_directory=works/log —hparams=batch_size=4» , I get a error «ModuleNotFoundError: No module named ‘PIL'». Full log is as follows:
FP16 Run: False
Dynamic Loss Scaling: True
Distributed Run: False
cuDNN Enabled: True
cuDNN Benchmark: False
/qwork1/hlw74/ttswork/tacotron2/layers.py:35: UserWarning: nn.init.xavier_uniform is now deprecated in favor of nn.init.xavier_uniform_.
self.conv.weight, gain=torch.nn.init.calculate_gain(w_init_gain))
/qwork1/hlw74/ttswork/tacotron2/layers.py:15: UserWarning: nn.init.xavier_uniform is now deprecated in favor of nn.init.xavier_uniform_.
gain=torch.nn.init.calculate_gain(w_init_gain))
Epoch: 0
train.py:219: UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number
if hparams.distributed_run else loss.data[0]
train.py:227: UserWarning: torch.nn.utils.clip_grad_norm is now deprecated in favor of torch.nn.utils.clip_grad_norm_.
model.parameters(), hparams.grad_clip_thresh)
Train loss 0 50.199665 Grad Norm 23.629131 3.03s/it
train.py:144: UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number
if distributed_run else loss.data[0]
Validation loss 0: 39.167839
Traceback (most recent call last):
File «train.py», line 291, in
args.warm_start, args.n_gpus, args.rank, args.group_name, hparams)
File «train.py», line 250, in train
reduced_val_loss, model, y, y_pred, iteration)
File «/qwork1/hlw74/ttswork/tacotron2/logger.py», line 34, in log_validation
iteration)
File «/usr/local/python3/lib/python3.6/site-packages/tensorboardX/writer.py», line 338, in add_image
self.file_writer.add_summary(image(tag, img_tensor), global_step)
File «/usr/local/python3/lib/python3.6/site-packages/tensorboardX/summary.py», line 158, in image
image = make_image(tensor)
File «/usr/local/python3/lib/python3.6/site-packages/tensorboardX/summary.py», line 164, in make_image
from PIL import Image
ModuleNotFoundError: No module named ‘PIL’
*** Error in `/usr/bin/python’: double free or corruption (!prev): 0x00000000025cf470 ***
Aborted (core dumped)
The text was updated successfully, but these errors were encountered:
yliess86 commented Jun 12, 2018 •
It says you don’t have the PIL (pillow) python library installed.
Have you tried these commands ?
sudo pip3 install pillow
or
sudo apt-get install python3-PIL
python3—no module named PIL #3825
Comments
ljh0279 commented Nov 22, 2017
when i Loading and normalizing CIFAR10, said that ‘from PIL import Image
ModuleNotFoundError: No module named ‘PIL».
However, PIL only supports python2.7, how can i solve it?
The text was updated successfully, but these errors were encountered:
Gosicfly commented Nov 22, 2017
just try this:
pip3 install pillow
ljh0279 commented Nov 22, 2017
pillow is already installed. However, it does not work.
zou3519 commented Nov 22, 2017
I would recommend uninstalling Pillow, PIL (if they exist) and reinstalling pillow.
Something like:
In the future you should post your question to https://discuss.pytorch.org/ , we like to keep issues on github to PyTorch-only bugs.
ljh0279 commented Nov 22, 2017
ok. thank you! it works. I will post these questions to there in the future.
KingCyrus commented Nov 2, 2019
I would recommend uninstalling Pillow, PIL (if they exist) and reinstalling pillow.
Something like:
You saved my career! I have been on this for weeks. Thanks.
Taulant8 commented Nov 19, 2019
I would recommend uninstalling Pillow, PIL (if they exist) and reinstalling pillow.
Something like:
In the future you should post your question to https://discuss.pytorch.org/ , we like to keep issues on github to PyTorch-only bugs.
Great job man , IT WORKED !
lukhuak commented Feb 23, 2020
It works in:
Set path of NetBeans11.2 IDE to the interpreter anaconda in python 3.7.4
import cv2
import numpy as np
from PIL import Image
indolentdeveloper commented May 7, 2020
you might get below error in mac.
WARNING: The directory ‘/Users//Library/Caches/pip’ or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that director
user -H option to uninstall
e.g. sudo -H pip3 uninstall PIL
uaahacker commented Nov 21, 2020
C:\Users\uaahacker>pip uninstall Pillow
Found existing installation: pillow 7.2.0
Uninstalling pillow-7.2.0:
Would remove:
c:\users\uaahacker\anaconda3\lib\site-packages\pil*
c:\users\uaahacker\anaconda3\lib\site-packages\pillow-7.2.0.dist-info*
Proceed (y/n)? y
Successfully uninstalled pillow-7.2.0
C:\Users\uaahacker>pip uninstall PIL
WARNING: Skipping PIL as it is not installed.
C:\Users\uaahacker>pip install Pillow
Collecting Pillow
Downloading Pillow-8.0.1-cp38-cp38-win_amd64.whl (2.1 MB)
|████████████████████████████████| 2.1 MB 261 kB/s
Installing collected packages: Pillow
Successfully installed Pillow-8.0.1
C:\Users\uaahacker>pip install PIL
ERROR: Could not find a version that satisfies the requirement PIL (from versions: none)
ERROR: No matching distribution found for PIL
Ali-Kamel commented Jan 10, 2021
I would recommend uninstalling Pillow, PIL (if they exist) and reinstalling pillow.
Something like:
In the future you should post your question to https://discuss.pytorch.org/ , we like to keep issues on github to PyTorch-only bugs.
thank you it worked for me aswell !
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
No Module named PIL
I know PIL is deprecated, so I installed Pillow instead, and for backward compatibility reason, Pillow is still using PIL as its module name. Here’s my pip freeze look like for Pillow: Pillow=3.2.0
Here’s how I use it in my code:
As someone suggested in a similar post, also, I tried
Neither works. Both give me this error:
Help is really appreciated!
7 Answers 7
As per my comment since it helped you out and answered your problem:
The issue that you were seeing is that you had pip version 1.5.6, and the version of pip does dictate how packages are unzipped, which ultimately determines whether or not modules are loaded properly.
All that is needed is:
Which allows pip to upgrade itself.
Use sudo if you’re on Mac/Linux, otherwise you’ll likely need to ‘Run as Administrator’ on Windows.
And voila, you can now properly import the PIL modules:
In my case, on Windows, all I needed to do is to run:
pip install pillow
You can use python -m pip install Pillow or pip install Pillow
I’m having this trouble too recently, so let me share my take on this. I’m on Mac OS X Mojave 10.14. I tried running the pip install pillow so many times blindly without finding deeper understanding as to where my python searches for its packages.
I encountered this error when I upgraded from OS X High Sierra to Mojave. My previously working Scrapy project just stopped running properly.
Note that I didn’t use virtualenv .
First, you need to check which python is used by the system. In the Terminal, run
You’ll get something similar to this:
nicholaslie$ which -a python /usr/local/bin/python /usr/local/bin/python /usr/bin/python
This leads me to searching inside the /usr/local/ folder. Turns out there’s a folder to where my python is searching its packages, and that is inside /usr/local/lib/python2.7 ( python ) or /usr/local/lib/python3.7 ( python3 )
What my current pip install pillow do is installing the PIL package inside the /usr/local/lib/python2.7/site-packages directory, but not to /usr/local/lib/python3.7/site-packages
However, since my project uses Python 3, No module named PIL error simply tells you that the python3 instance you’re using cannot find the PIL library.
I used Homebrew for managing my system packages such as node , python , etc. So what I did was reinstall python3 with Homebrew with:
brew reinstall python , then run pip3 install pillow .
Just ensure that the PIL package is installed properly in /usr/local/lib/python3.7/site-packages and you should be good to go. Hope this helps someone.
Python — ModuleNotFoundError: No module named
I’m new in Python and I’m having the following error with this simple example:
This is my project structure:
And this is the error when I execute the src/main.py file:
If I move the main.py file to the root and then I execute this file again, works. but is not working inside src/ directory
This is my main.py :
Note: When I execute the same code from Pycharm is working fine, but not from my terminal.
5 Answers 5
Your PYTHONPATH is set to the current directory from the program you execute. So if you’re executing something inside a directory src , it will never be able to find the directory lib because it’s outside the path. There’s a few choices;
- Just move lib/ into src/ if it belongs to your code. If it’s an external package, it should be pip installed as Henrique Branco mentioned.
- Have a top-level script outside of src/ that imports and runs src.main . This will add the top-level directory to python path.
- In src/main.py modify sys.path to include the top-level directory. This is usually frowned upon.
- Invoke src/main.py as a module with python -m src.main which will add the top-level directory to the python path. Kind of annoying to type, plus you’ll need to change all your imports.
If I may add to MarkM’s answer, if you wanted to keep your current directory structure and still make it work, you could add a setup.py in your root dir, where you can use setuptools to create a package you could install.
If your file had something along the lines of:
And then you do pip install [—user] -e path/to/directory you’ll get an «editable package» which will effectively a symlink to the package in your development directory, so any changes you make will not require a reinstall (unless of course you rejig package structure or add/remove/edit entry points).
This does assume your src/main.py has a main function.
You’ll also need __init__.py files in your «package» directories, even in Python3, as otherwise Python assumes these are namespace packages (Won’t go into detail) and the find_packages() call won’t find them.
This will also allow your relative imports to work. Absolute imports will only work when invoking the script from your entry point but not when calling the script directly in your development directory.
Ошибка «ModuleNotFoundError: No module named ‘setuptools’» (РЕШЕНО)
При установки пакетов Python с помощью pip или setup.py может возникнуть ошибка «No module named ‘setuptools’».
Эта ошибка появляется при использовании команды:
Файл setup.py и pip нуждаются в setuptools. Некоторые пакеты Python используют для развёртывания distutils, но в настоящее время большинство использует setuptools.
Setuptools — это расширение для python-distutils для больших и сложных развёртываний.
То есть указанная ошибка возникает из-за отсутствия пакета setuptools. Его можно установить несколькими способами.
Если у вас Ubuntu, Linux Mint, Debian или производный от них дистрибутив, то вы можете установить этот пакет из стандартных репозиториев:
Если вы уже установили PIP (а именно пакет python3-pip), то вместо указанной выше команды, можно выполнить такую:
Выберите первую или вторую, не нужно выполнять их обе.
Если у вас Windows, то установка делается так:
Как переустановить setuptools
Если у вас уже есть setuptools, но его версия слишком старая и возникают проблемы при обновлении, то переустановите его следующим образом (должен быть установлен пакет python3-pip, это делается командой sudo apt install python3-pip):