The _imaging C module is not installed (on windows)

2024/10/12 18:21:13

I'm trying to generate some pdf with django/PIL/Imaging and everything is good until I attempt to put some images into the pdf:

Exception Type: ImportError
Exception Value:    
The _imaging C module is not installed
Exception Location: D:\install\python27\lib\site-packages\PIL\Image.py in __getattr__, line 37
Python Executable:  D:\install\python27\python.exe
Python Version: 2.7.1
Python Path:    
['D:\\~Sasha\\Portman','D:\\install\\python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg','D:\\install\\python27\\lib\\site-packages\\pisa-3.0.33-py2.7.egg','D:\\install\\python27\\lib\\site-packages\\html5lib-0.95-py2.7.egg','D:\\install\\python27\\lib\\site-packages\\pypdf-1.13-py2.7.egg','D:\\install\\PyCharm 2.0.2\\helpers','D:\\~Sasha\\Portman','D:\\~Sasha','C:\\Windows\\system32\\python27.zip','D:\\install\\python27\\DLLs','D:\\install\\python27\\lib','D:\\install\\python27\\lib\\plat-win','D:\\install\\python27\\lib\\lib-tk','D:\\install\\python27','D:\\install\\python27\\lib\\site-packages','D:\\install\\python27\\lib\\site-packages\\PIL']

PIL was installed via pre-compiled bundle from PIL website and importing _imaging was giving this output:

Python 2.7.1 (r271:86832, Feb  7 2011, 11:33:02) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import _imaging
Traceback (most recent call last):File "<stdin>", line 1, in <module>
ImportError: DLL load failed: %1 is not a valid Win32 application.

Could python x64 be causing this issue?

Python 2.7.1 (r271:86832, Feb  7 2011, 11:33:02) [MSC v.1500 64 bit (AMD64)] on win32

I got a pre-built package for x64 of PIL and installed it on top of existing bundle, now import via console does work:

>>> import _imaging
import _imaging # dynamically loaded from D:\install\python27\lib\site-packages\PIL\_imaging.pyd

but I keep getting the same error whilst trying to generate the pdf file.

Answer

Yes, this could definitely be (and most likely is) caused by an x64 issue. If you're running Python x64, any module that includes a native DLL needs to be installed in a version compiled for x64 too.

Edit: I cannot find an actual precompiled version for x64 at the PIL site, but here is a starting point if you're interested in compiling it yourself.

https://en.xdnf.cn/q/69622.html

Related Q&A

HOW TO use fabric use with dtach,screen,is there some example

i have googled a lot,and in fabric faq also said use screen dtach with it ,but didnt find how to implement it? bellow is my wrong code,the sh will not execute as excepted it is a nohup taskdef dispatc…

Developing for the HDMI port on Linux

How would it be possible to exclusively drive the HDMI output from an application, without allowing the OS to automatically configure it for display output?For example, using the standard DVI/VGA as t…

Hive client for Python 3.x

is it possible to connect to hadoop and run hive queries using Python 3.x? I am using Python 3.4.1.I found out that it can be done as written here: https://cwiki.apache.org/confluence/display/Hive/Hiv…

How to add a function call to a list?

I have a Python code that uses the following functions:def func1(arguments a, b, c):def func2(arguments d, e, f):def func3(arguments g, h, i):Each of the above functions configures a CLI command on a p…

How to do fuzzy string search without a heavy database?

I have a mapping of catalog numbers to product names:35 cozy comforter 35 warm blanket 67 pillowand need a search that would find misspelled, mixed names like "warm cmfrter".We have code u…

Logging while nbconvert execute

I have a Jupyter notebook that needs to run from the command line. For this I have the following command:jupyter nbconvert --execute my_jupyter_notebook.ipynb --to pythonThis command creates a python s…

How to provide input for a TensorFlow DNNRegressor in Java?

I managed to write a TensorFlow python program with a DNNRegressor. I have trained the model and is able to get a prediction from the model in Python by manually created input (constant tensors). I hav…

Adding breakpoint command lists in GDB controlled from Python script

Im using Python to control GDB via batch commands. Heres how Im calling GDB:$ gdb --batch --command=cmd.gdb myprogramThe cmd.gdb listing just contains the line calling the Python scriptsource cmd.pyAnd…

Getting the maximum accuracy for a binary probabilistic classifier in scikit-learn

Is there any built-in function to get the maximum accuracy for a binary probabilistic classifier in scikit-learn?E.g. to get the maximum F1-score I do:# AUCPR precision, recall, thresholds = sklearn.m…

Pydantic does not validate when assigning a number to a string

When assigning an incorrect attribute to a Pydantic model field, no validation error occurs. from pydantic import BaseModelclass pyUser(BaseModel):username: strclass Config:validate_all = Truevalidate_…