Skip to content Skip to sidebar Skip to footer

How Do I Install OpenJPEG On Windows And Use It With Pillow?

I would like to use the Python Pillow library to save 16 bit gray scale arrays in the jp2 ('JPEG 2000') format. I have hit a brick wall in trying to install the required library Op

Solution 1:

I've just installed Pillow with an installer from here. I chose Pillow-4.0.0.win-amd64-py3.5.exe. During install it found conda's python and properly chose where to install (it installed to a root environment).

Code to test it works:

from PIL import Image
import numpy as np
arr = np.ones(dtype=np.uint16, shape=(100,100))
im = Image.fromarray(arr)
im.save('test.jp2') 

Note, that saved file has 8 bpp.


Solution 2:

Anaconda build Python using different version of the microsoft visual studio tools.

Each version of those tools has its own runtime, which is incompatible with other versions.

The Pillow library used compiled shared libraries. You will need to compile OpenJPEG with exactly the same version of the ms visual studio tools that was used to build Python and Pillow.


Solution 3:

For general reference.

The Windows equivalent to 'nix .so files have the extension .dll (sic - "Windows Binaries" - dynamic linked library); and yes, the file has to reside somewhere in the system PATH.

Being in the PATH allows Windows to find the file, but that's not enough. Windows has to be told what can be done with it; that it's a shareable library. That's done by:

1) Open a DOS Command Prompt in the (sub)directory where the binary is located; e.g. C:\LIBS

2) Run the command "regsvr32 filename.dll". This registers the .dll as a shared file (in Windows Registry), so that Windows knows how to load it into memory and let user applications access it.

You can actually run regsvr32 from any directory (it's a System file & should be somewhere in the C:\Windows\system32 directory; but it's more convenient to run in the same directory as the .dll because otherwise you have to prepend filename.dll with the entire directory tree from C:\ to where ever the file is located.

You can run "regsvr32" with no target filename to get a popup list of command-line switches which can be used.


Post a Comment for "How Do I Install OpenJPEG On Windows And Use It With Pillow?"