I'm not sure why but I always have an issue with importing PIL. No matter how I try to import it, it just never seems to work. I have tried to install it or update it. I have even tried with Pillow but still nothing. any help is greatly appreciated as it's something so little but so annoying. I am using python 3.10 enter image description here
PIL is deprecated, it's a very old library. Its current maintained fork can be installed via pip install Pillow.
Related
I have run the same code(with packages I needed) before and it worked, not sure what's happening now. This show the error,
AttributeError: module 'PIL.Image' has no attribute 'Resampling'. Probably it's small issue, but I can't figure it out, I am working in databricks.
I had the same problem. The easy way is use the old version of Pillow.
pip install Pillow==9.0.0
And your code should work.
Note: You can also use
pip install --ignore-installed Pillow==9.0.0
If for some reason, pip is refusing to install it. Note, however, that it can break dependencies, so use it only as a last resort.
I had the same problem and found that I need to replace PIL.Image.Resampling.BICUBIC with PIL.Image.BICUBIC.
I am using pillow version 7.1.2
from PIL import Image
im = Image.open('image.png')
im2 = im.resize((512,512),resample=Image.BICUBIC)
display(im2)
The resampling enums were seemingly added in Pillow 9.1.0 (released 3 days ago) via this pull request.
I would imagine your Databricks environment has a different verison.
I find that forcing the use of a particular Pillow version may break other packages.
Another solution that works for any Pillow version and avoids deprecation warnings is to insert the code:
import PIL.Image
if not hasattr(PIL.Image, 'Resampling'): # Pillow<9.0
PIL.Image.Resampling = PIL.Image
# Now PIL.Image.Resampling.BICUBIC is always recognized.
my way to fix it:
pip install --ignore-installed Pillow==9.3.0
Same happened when I upgraded some module. I just restarted runtime and it helped.
In my case, pip install Pillow==9.1.0 is suitable for my code
I have opencv-python installed and the .pyd file is added in the site-packages and the DLLs. The code works with images. When I want to read, show, write an image it works. But I get a warning that the functions' references cannot be found in init.py . Due to this, I can not use the auto-complete feature. Could someone help me out? I am using opencv 3.4.0 and python 3.6.4 in pycharm. I downloaded opencv via pip in the command prompt.
The problem is caused by CV2 and how __init__.py does the imports. Just ignore the warnings the program will work all the same, or you can do an import with an alias like:
import cv2.cv2 as cv2
If you have a warning on it press Alt+Enter to install and fix it. Now you will have the code completion and no other warnings (about that) on the project.
Switching to an older version of opencv solved this problem for me.
Apparently pycharm sometime breaks depending on the version of opencv. For me, the newest version was, 4.6.X unstalling and installing 4.5.X did the trick.
I use python 3.10 and my newest version for opencv is 4.6.0.66 ,by changing opencv version to 4.5.5.62 and with an alias: import cv2.cv2 as cv2 my problem has solved.
Import cv2 as follows:
from cv2 import cv2
I installed version 4.5.5.64 and imported with an alias.
import cv2.cv2 as cvv2
I was using Python 3.10.2288.0 and OpenCV 1.6.0.66.
I resolved the issue by rolling back the OpenCV version to 4.5.5.62.
I am using macOS and installed pillow in the terminal with code pip3 install pillow and I got the version 8.0.1.
But I cannot import it in Pycharm. I typed from PIL import Image and an error message show ModuleNotFoundError: No module named 'PIL' . then I changed PIL to pillow from pillow import Image, it works but cannot find Image class.
How can I fix it?
Is very likely that your Pycharm has created a virtual environment for the project and is not using the same library as the python on the system.
If that is the case, go to Settings > Project > Python Interpreter, press on the plus sign (+), write Pillow on the search bar, select the right package, and add it to your interpreter running on PyCharm.
I recommend the use of the pipenv tool to manage your project dependencies for each project. It helps you to maintain the project dependencies separated from the system or other projects.
Pillow not pillow.
run pip uninstall pillow then run pip install Pillow.
Not sure if the solutions given have worked for everyone but try but writing the imports out separately. I tried everything and by accident this worked. So try as below, I hope this works for anyone who needs the help
from PIL import Image
from PIL import ImageTk
I've heard/read alot about the PIL module but i cant get it to work with the current version of Python.
Is there another to just open a simple PNG/JPG/JPEG file and show it ?
With kind regards,
PIL has not yet released a Python 3.x update. Instead, consider Pillow.
Here is the link to Pillow at The Cheese Shop (PyPi), and a link to some docs for it.
Additionally, you could install it through pip, thusly:
pip install pillow
I have installed PIL with homebrew. It then says that there was a symlink error, and that is can be easily fixed by doing it again, but with a sudo. I did so. Now, when I go into python, and import Image, it doesn't work! I've tried import PIL, import image, import pil, and none of them work. When I try to install it again, it says Error: pil-1.1.7 already installed. Please help!
I think you would see this issue if you were using the python binary that was not installed by homebrew along with a package that you did install via homebrew. Could you verify that the python binary you are using is not the one that was included in OS X by default?