-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_imaging Failed to Import in from PIL import Image #5573
Comments
Pillow 8.3.0 wheels for Windows are built with libtiff 4.3.0, which has a new dependency (LERC) that uses C++ code and requires the C++ runtime library (MSVCP140.DLL). I think we need to package that DLL in the wheels. |
No. Copying the msvc runtime DLLs from the Visual Studio redist directory to the PIL directory before building the wheel seems enough.
No. Those DLLs are redistributable. |
Is there any work-around for this, or fix? |
@KushalSM I suggest just using Pillow 8.2 instead. If you're using pip, the command would be |
Ok thank you very much |
Download and install the Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019 vc_redist.x64.exe (64-bit) and vc_redist.x86.exe (32-bit). Many Python extension packages depend on having the redistributable installed: matplotlib, Pandas, scikit-image... |
I have many redistributables installed which include 2015-2019. Python 3.9.1 |
That is a different issue. The original issue is solved by installing the missing C++ runtime. |
This reminded me that last week I installed an older version of Visual Studio (2017) which was required for some work. So, before I created a new issue here, I tried rerunning the vc_redist to see if a repair would fix the issue. Turns out it did. Thanks for the nudge to do so, I can't say for sure that it was because of VS 2017 but there certainly was an issue with the runtime. |
Just a +1: installing the VC redist (https://support.microsoft.com/en-us/topic/the-latest-supported-visual-c-downloads-2647da03-1eea-4433-9aff-95f26a218cc0) fixed this for me. I couldn't figure out why it worked on my build machine and not my server. |
To those still having this issue, could you try again with Pillow 8.3.1? |
@radarhere I have the same issue with Pillow 8.3.1.
|
@radarhere I can confirm that with Pillow 8.3.1 and installing |
Ahhhh. Looks like the 64-bit wheel build packaged the 32-bit runtime DLLs for whatever reason. |
@cgohlke it looks very much like it. |
@radarhere Do you have any experience with uploading fixed wheels with an added build tag, e.g. |
I don't, but I'm game to give it a try, as long as there's no objection from @hugovk |
No objection! |
The existing 64-bit wheels can be fixed and repackaged with a build number, e.g.:
To verify that this fixes the issue, install Python and the wheel in a Windows 10 Sandbox (unlike development and CI systems, the Sandbox doesn't have the C++ runtime installed). E.g.: def test_pillow_wheel(
wheel='Pillow-8.3.1-1-cp39-cp39-win_amd64.whl',
pythonurl='https://www.python.org/ftp/python/3.9.6/python-3.9.6-amd64.exe',
test='_test_pillow_wheel',
):
"""Test a local Pillow wheel in a Windows 10 Sandbox.
1. write Python, Command, and Windows 10 Sandbox scripts to the current
directory.
2. run the Windows sandbox script, which runs the command script, which
downloads and installs Python, pip installs the wheel, and runs the
Python script.
3. on successful execution of the scripts, display an image containing
Pillow version information in Microsoft Paint.
4. open the log output in notepad.
"""
import os
pythonexe = pythonurl.rsplit('/', 1)[-1]
testdir = rf'C:\Users\WDAGUtilityAccount\Desktop\{test}'
logfile = f'{testdir}\{test}.txt'
with open(test + '.wsb', 'w') as fh:
fh.write(
rf"""<!-- {test}.wsb -->
<Configuration>
<MappedFolders>
<MappedFolder>
<HostFolder>{os.path.dirname(__file__)}</HostFolder>
<SandboxFolder>{testdir}</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
</MappedFolders>
<LogonCommand>
<Command>{testdir}\{test}.cmd</Command>
</LogonCommand>
</Configuration>"""
)
with open(test + '.cmd', 'w') as fh:
fh.write(
rf""":: {test}.cmd
curl {pythonurl} --output {testdir}\{pythonexe} > {logfile} 2>&1
{testdir}\{pythonexe} /passive Include_tcltk=0 Include_test=0 Include_dev=0 ^
>> {logfile} 2>&1
assoc .png=Paint.Picture
py -m pip install {testdir}\{wheel} >> {logfile} 2>&1
py {testdir}\{test}.py >> {logfile} 2>&1
start {logfile}
"""
)
with open(test + '.py', 'w') as fh:
fh.write(
f"""# {test}.py
import sys
from PIL import Image, ImageDraw
im = Image.new('L', (512, 64))
dr = ImageDraw.Draw(im)
dr.text(
(0, 0), text=sys.version + '\\nPillow ' + Image.__version__, fill='white'
)
im.show()
"""
)
os.system(test + '.wsb')
test_pillow_wheel() The fixed 64-bit wheels are here. |
@cgohlke would you like me to upload those to PyPI now, or do you feel like someone here should check them first? |
Anyone still having this issue interested in trying one of those wheels? - https://www.lfd.uci.edu/~gohlke/download/Pillow-8.3.1-1-win-dist.zip |
Yes, please upload the new wheels to PyPI. I tested them locally in a Sandbox with the provided script. |
Ok, done. Anyone with this issue should now be able to re-install from PyPI to resolve the matter. |
@johnsunxu does re-installing from PyPI resolve this for you? |
pip install Pillow-8.3.1 “install the Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019” Can't solve the problem |
Look, my OS is Windows 10 and my Python is 3 and Pillow is 9.5.0, and i'm getting the import error called "cannot import _imaging", u got any way to fix it? plz reply if u do |
Could you try uninstalling Pillow, check that you can no longer
|
Hey! think i actually fixed it! THX! |
Hi, I've run into the same issue with |
We don't actually create the wheels distributed on conda. You may want to talk to /~https://github.com/conda-forge/pillow-feedstock instead. |
Alright, thanks @radarhere |
Hey, i've tried a lot of things from different websites including this one and it is still not working any updates ? |
What is exact command you used to install Pillow? |
|
@jerz4re This particular issue "bad windows wheels" was fixed 2 years ago. Whether or not you are having that issue is TBD. If you are, try this. Most important, try uninstalling Pillow and make sure you can't import PIL before you do anything else. |
What did you do?
from PIL import Image
What did you expect to happen?
Image would import without errors
What actually happened?
What are your OS, Python and Pillow versions?
I installed PIL 8.3 today and then ran into the _imaging import issue. There were previous old threads on a similar problem which mentioned reinstalling pillow but that did not work. I tried importing Image from a different device with python 3.9.5 and Pillow 8.3 without any issues so I then reinstalled python 3.9.5 on the device where pillow did not work. After reinstalling python, Pillow still ran into the same importing problems.
To get pillow to work I had to pip install version 8.2
The text was updated successfully, but these errors were encountered: