I got this error while importing Image
from PIL import Image
Traceback (most recent call last):
File "<ipython-input-13-b7f01c2f8cfe>", line 1, in <module>
from PIL import Image
File "/lib/python3.7/site-packages/PIL/Image.py", line 40, in <module>
from . import PILLOW_VERSION, ImageMode, TiffTags, __version__, _plugins
**ImportError:** cannot import name 'PILLOW_VERSION' from 'PIL' (unknown location)
I tried to remove it by myself but then got the same problem with __version__, then _plugins
Updating doesn't work for me. Can you help please?
How did you install Pillow?
Googling, I would conclude that there is something strange about your installation, rather than anything specific to Pillow. I would be curious about what is printed by this code, and whether it makes a difference -
import sys
print(sys.path)
sys.path.append('/lib/python3.7/site-packages')
from PIL import Image
@radarhere i did it by usual way pip3 install Pillow.
After this:
import sys
print(sys.path)
sys.path.append('/lib/python3.7/site-packages')
from PIL import Image
I got another an import error but different:
ImportError: cannot import name '_imaging' from 'PIL' (/lib/python3.7/site-packages/PIL/__init__.py).
Should I reinstall it by some specific way?
Installing it through pip should be fine. What operating system are you using?
Have you tried uninstalling it and re-installing it to see if that fixes anything?
@radarhere , yeah, of course I did...
Ubuntu 18.0
Thanx for you help, now I see it's maybe some enviroment problem.
Another thought - considering that the first problem means that Python wasn't able to import the package correctly in some way, you might try python -m pip install Pillow instead of just pip install Pillow, as that will ensure that the same Python is being used for pip as for the running of your script.
@poormag if you resolve this, be sure to let us know, so we can close the issue, and maybe leave a note of the solution for the sake of anyone arriving here in the future.
Thanks for using Pillow. Unfortunately it is harder to remotely debug install problems.
For _imaging, I would check in the installed PIL directory to see if there is an _imaging*.so file.
For another idea, import PIL.Image as Image might conceivably produce a different result.
Python 3.8 has also been released. While not a solution to your problem, you may be interested in upgrading, and that new environment may work for you.
I'm getting the same error right now after conda install pillow on Win 10.
It installed pillow 6.2.1, python is 3.6.9.
Looks like downgrading to pillow 6.1 helps.. after conda install pillow=6.1 the error is gone.
@stmax82 Please report Conda issues to https://github.com/conda-forge/pillow-feedstock.
It sounds a bit like https://github.com/conda-forge/pillow-feedstock/issues/66 ("DLL import fails in fresh conda install"), fixed yesterday.
I'll close this issue, @poormag let us know if this is still a problem with pip and we can re-open.
I met the same problem. I am using python3.7.5 on macos. When using pip install Pillow, pillow 7.0.0 was installed. I received ImportError: cannot import name 'PILLOW_VERSION' from 'PIL'. When I specify the version pip install Pillow==6.1, the problem is gone.
@WeiQijie In 7.0.0:
PILLOW_VERSIONhas been removed. Use__version__instead.
https://pillow.readthedocs.io/en/stable/releasenotes/7.0.0.html#pillow-version-constant
I met the same problem. I am using python3.7.5 on macos. When using
pip install Pillow, pillow 7.0.0 was installed. I receivedImportError: cannot import name 'PILLOW_VERSION' from 'PIL'. When I specify the versionpip install Pillow==6.1, the problem is gone.
This one worked for me, thanks for sharing, I really struggled with this the whole Day. Thanks again!
I recommend updating your code to use from PIL import __version__ instead of from PIL import PILLOW_VERSION (or similar).
__version__ has been available since Pillow 3.4.0 (October 2016, https://github.com/python-pillow/Pillow/pull/2027), so works in Pillow 6. You should require pillow>=3.4.0, and I suggest using the latest 7.0.0 as several security fixes have been made since 3.4.0.
If you still need to work with pillow<3.4.0:
try:
from PIL import __version__
except ImportError:
from PIL import PILLOW_VERSION as __version__
I had the same error when using docker to build a Linux based image in Windows 10 with fastai. Added "RUN pip install Pillow==6.1" above "RUN pip install fastai" in the Dockerfile and following the build, the container successfully ran. Thanks for your posts.
had the same error while using pytorch code which had deprecated pillow code. since PILLOW_VERSION was deprecated, i worked around it by:
Simply duplicating the _version file and renaming it as PILLOW_VERSION.py in the same folder.
worked for me
@WeiQijie In 7.0.0:
PILLOW_VERSIONhas been removed. Use__version__instead.https://pillow.readthedocs.io/en/stable/releasenotes/7.0.0.html#pillow-version-constant
perhaps one of the most stupid things ever done. Boycotting 7.0.0 version Rolling back to 6.2.2
torchvision v0.5.0 has been released with the fix:
torchvision>=0.5.0@hugovk can someone release the Windows version of torchvision 0.5.0 to pipy and conda?
https://github.com/pytorch/vision/tree/master/packaging
Last version with a Windows wheel is https://pypi.org/project/torchvision/0.4.1/#files
Looks like something dropped the Windows versions after that?
https://pypi.org/project/torchvision/0.5.0/#files
@asears Please ask at the torchvision project. This might be the right place: https://github.com/pytorch/vision/pull/1717
(Edit: fixed link, but https://github.com/pytorch/vision/issues/1756 seems relevant and I see you already commented there 👍)
Problem is the fact that PILLOW_VERSION is removed in 7.0
Either one can downgrade to the previous build (works for me) or better is that this change gets reflected in the touchvision source code.
in my case, I have Python 3.7.6 and I downgraded to the latest possible match
conda install pillow=6.2.1
I fixed the problem by just adding the code ‘PILLOW_VERSION='7.0.0'’ to the file '.../PIL/__init__.py'.
I don't know if there will be any problems, but it works now.
I fixed the problem by just adding the code ‘PILLOW_VERSION='7.0.0'’ to the file '.../PIL/init.py'.
I don't know if there will be any problems, but it works now.
It's working! It's really working!
(Just adding the code PILLOW_VERSION='7.0.0' to the beginning of the file
'.../Lib/site-packages/PIL/__init__.py'.)
I just set pillow version when I imported code
import PIL
PIL.PILLOW_VERSION='7.0.0'
import PIL.Image as Image
IDK
чт, 2 апр. 2020 г. в 11:33, Antupis notifications@github.com:
I just set pillow version when I imported code
`
import PILPIL.PILLOW_VERSION='7.0.0'
import PIL.Image as Image
`—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/python-pillow/Pillow/issues/4130#issuecomment-607702538,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ALH6ZJDDNPZS6N24MBH5PB3RKREWPANCNFSM4I7XCONQ
.
Try this method:
First, uninstall the Pillow package from your system
Simple method!
if the Error is (Given below), the above method will work.
Traceback (most recent call last):
File "main.py", line 3, in <module>
from PIL import Image
File "C:\Users\shane\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\Image.py", line 44, in <module>
from . import (
ImportError: cannot import name '_raise_version_warning' from 'PIL' (C:\Users\shane\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\__init__.py)
The method is tested on windows and ubuntu
@shanethomas1029 hi, sorry, not quite following. What triggered the error cannot import name 'raise_version_warning' from 'PIL'?
I's already done:
PILLOW_VERSION='7.0.0'
And it's working ...
вс, 5 апр. 2020 г. в 14:17, shanethomas1029 notifications@github.com:
Try this method:
First, uninstall the Pillow package from your system
- python -m pip uninstall Pillow
Second, Reinstall it!- python -m pip install Pillow
Simple method!
if the Error is (Given below), the above method will work.
Traceback (most recent call last):
File "main.py", line 3, in
from PIL import Image
File
"C:\Users\shane\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\Image.py",
line 44, in
from . import (
ImportError: cannot import name 'raise_version_warning' from 'PIL'
(C:\Users\shane\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL_init
.py)The method is tested on windows and ubuntu
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/python-pillow/Pillow/issues/4130#issuecomment-609400203,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ALH6ZJGEDHWKZ2GMGYGJIB3RLBSERANCNFSM4I7XCONQ
.
from torchvision import models
from torchvision import datasets
from torchvision import ops
from torchvision import transforms
from torchvision import utils
from torchvision import io
try:
from .version import __version__ # noqa: F401
except ImportError:
pass
_image_backend = 'PIL'
PILLOW_VERSION='7.0.0'
def set_image_backend(backend):
"""
Specifies the package used to load images.
Args:
backend (string): Name of the image backend. one of {'PIL', 'accimage'}.
The :mod:`accimage` package uses the Intel IPP library. It is
generally faster than PIL, but does not support as many operations.
"""
global _image_backend
if backend not in ['PIL', 'accimage']:
raise ValueError("Invalid backend '{}'. Options are 'PIL' and 'accimage'"
.format(backend))
_image_backend = backend
def get_image_backend():
"""
Gets the name of the package used to load images
"""
return _image_backend
@shanethomas1029 hi, sorry, not quite following. What triggered the error
cannot import name 'raise_version_warning' from 'PIL'?
You got it?
I's already done: PILLOW_VERSION='7.0.0' And it's working ... вс, 5 апр. 2020 г. в 14:17, shanethomas1029 notifications@github.com:
Try this method: First, uninstall the Pillow package from your system 1. python -m pip uninstall Pillow Second, Reinstall it! 2. python -m pip install Pillow Simple method! if the Error is (Given below), the above method will work. Traceback (most recent call last): File "main.py", line 3, in from PIL import Image File "C:\Users\shane\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\Image.py", line 44, in from . import ( ImportError: cannot import name 'raise_version_warning' from 'PIL' (C:\Users\shane\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL_init .py) The method is tested on windows and ubuntu — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#4130 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALH6ZJGEDHWKZ2GMGYGJIB3RLBSERANCNFSM4I7XCONQ .
from torchvision import models from torchvision import datasets from torchvision import ops from torchvision import transforms from torchvision import utils from torchvision import io try: from .version import __version__ # noqa: F401 except ImportError: pass _image_backend = 'PIL' PILLOW_VERSION='7.0.0' def set_image_backend(backend): """ Specifies the package used to load images. Args: backend (string): Name of the image backend. one of {'PIL', 'accimage'}. The :mod:accimagepackage uses the Intel IPP library. It is generally faster than PIL, but does not support as many operations. """ global _image_backend if backend not in ['PIL', 'accimage']: raise ValueError("Invalid backend '{}'. Options are 'PIL' and 'accimage'" .format(backend)) _image_backend = backend def get_image_backend(): """ Gets the name of the package used to load images """ return _image_backend
Okay
Thanks
OK
пн, 6 апр. 2020 г. в 12:37, shanethomas1029 notifications@github.com:
@shanethomas1029 https://github.com/shanethomas1029 hi, sorry, not
quite following. What triggered the error cannot import name
'raise_version_warning' from 'PIL'?You got it?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/python-pillow/Pillow/issues/4130#issuecomment-609685526,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ALH6ZJGTEXBWAQLAVYKTROLRLGPEPANCNFSM4I7XCONQ
.
Such an unnecessary changes. It almost feel like people here are bored and trying to find ways to broke old codes.
Thanks for fix btw @zealousfool
PILLOW_VERSION was re-added in Pillow 7.1.0, released 2020-04-01, to give projects more time to upgrade:
PILLOW_VERSIONwas re-added in Pillow 7.1.0, released 2020-04-01, to give projects more time to upgrade:
- https://pillow.readthedocs.io/en/stable/releasenotes/7.1.0.html#pillow-version-constant
- https://pillow.readthedocs.io/en/stable/deprecations.html#pillow-version-constant
- #4494
I can verify that:
python -m pip uninstall Pillow
python -m pip install Pillow
Reinstalling/installing Pillow 7.1.0 fixes the problem.
Hello.
OK.
Thank you!
It's working now too.
I DID it!
It's more prefer to use some installations than to write the code ...
Good-bye!
пт, 10 апр. 2020 г. в 18:30, Greg Tarr notifications@github.com:
PILLOW_VERSION was re-added in Pillow 7.1.0, released 2020-04-01, to give
projects more time to upgrade:-
https://pillow.readthedocs.io/en/stable/releasenotes/7.1.0.html#pillow-version-constant
-
https://pillow.readthedocs.io/en/stable/deprecations.html#pillow-version-constantI can verify that:
python -m pip uninstall Pillow
python -m pip install PillowReinstalling/installing Pillow 7.1.0 fixes the problem.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/python-pillow/Pillow/issues/4130#issuecomment-612079762,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ALH6ZJE7W6H5UQL4BC7QDNTRL43RXANCNFSM4I7XCONQ
.
Add the following line to your_path\Anaconda\Lib\site-packages\PIL__init__.py:
PILLOW_VERSION = _version.__version__
I met the same problem. I am using python3.7.5 on macos. When using
pip install Pillow, pillow 7.0.0 was installed. I receivedImportError: cannot import name 'PILLOW_VERSION' from 'PIL'. When I specify the versionpip install Pillow==6.1, the problem is gone.This one worked for me, thanks for sharing, I really struggled with this the whole Day. Thanks again!
This works for me as well!
Most helpful comment
I'm getting the same error right now after
conda install pillowon Win 10.It installed pillow 6.2.1, python is 3.6.9.
Looks like downgrading to pillow 6.1 helps.. after
conda install pillow=6.1the error is gone.