How do I install OpenJPEG on Windows and use it with Pillow? - python-3.x

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 OpenJPEG on my Windows machine. The documentation is not very clear... but I assumed that I needed to download the Win64 binaries and simply put them on my path ( which I did).
That done, I am still getting the following error when using Pillow 4.0.0 in Anaconda 4.3.0 on Windows.
IOError: encoder jpeg2k not available
Anyone out there successfully used Pillow to write and read JPEG 2000 files, I would sure appreciate some tips.
Edit:
Here is the code that fails:
import PIL
import numpy as np
arr = np.ones(dtype=np.uint16, shape=(100, 100))
im = PIL.Image.fromarray(arr)
im.save('arr.jp2')

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.

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.

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.

Related

liboctinterp.so.3 - cannot open shared object file [duplicate]

I have two versions of Octave installed, version 3.6.4 installed via the package manager (Linux Mint Debian), and version 4.0.0 compiled from source. I also have numerous .oct files in a folder pointed to in an .octaverc file. My problem is that the version 4.0.0 cannot "see" these .oct files and if I try to call them the whole session crashes unless I recompile them under 4.0.0 with mkoctfile. However, doing this means that the version 3.6.4 cannot "see" them and trying to call them gives an error message
failed to load: liboctinterp.so.3: cannot open shared object file: No such file or directory
How can I get both versions to recognize my .oct functions without having to recompile them each time?
I copy the answer from Mike and Olaf from the help mailinglist (crossposting http://octave.1599824.n4.nabble.com/Oct-files-run-in-Octave-version-3-6-4-or-4-0-0-but-not-both-td4672690.html)
Short answer: you can't.
The Octave library API and ABI change between releases. Octave 3.6 was liboct{ave,interp}.so.1, Octave 3.8 was liboct{ave,interp}.so.2, and 4.0 is liboct{ave,interp}.so.3. These libraries are not forwards or backwards compatible.
You can compile your oct-files in two (or three?) different paths with the
wanted Octave version in the path.
If you want to install your files system-wide, a good candidate directory for the differently compiled oct-files seems to be
fullfile (OCTAVE_HOME (), "lib/octave/site/oct/", octave_config_info ("canonical_host_type"))
assuming OCTAVE_HOME () is different for each of your Octave versions. This directory seems to be in the path by default.
If not system-wide, you could check OCTAVE_VERSION () in your .octaverc and set the path differently for each version.

PyInstaller executable on Windows not working because of PortAudio library issues (OSError)

I'm trying to build a .exe on Windows from my Python 3.7 application using PyInstaller. The build appears to run smoothly and shows no errors; however, executing the file on the Windows command prompt results in this awful error:
OSError: PortAudio library not found
I've done some research about this problem and found some info, but still couldn't overcome it. My app uses the sounddevice library, which depends on PortAudio library. PortAudio is installed, since the app works perfectly when I run it directly using Python; the problem is, clearly, that PyInstaller tracks the dependencies in some different way and is not able to find it and link it to the build.
This 'different way' is, actually, calling the 'find_library' function from 'ctypes.util' Python library to find the PortAudio library on the system. So, I ran the following on Python and confirmed it is not able to find the libary.
Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] :: > Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
from ctypes.util import find_library
a = find_library('portaudio')
print(a)
None
So far, I've tried several solutions. First, I downloaded and compiled the last PortAudio version manually. Didn't work. Then, I tried using Anaconda instead of the official Python distribution; as you may know, Anaconda's package manager 'conda' can deal with C libraries like PortAudio. So I installed it on my Anaconda's virtual environment and tried to build my app in there. Didn't work either. I also tried adding PortAudio directory to Windows PATH variable, but it also failed. I'm kinda lost. The only idea I have yet to try is building it on Linux using Wine, but I suspect there might be a way to get it working on Windows.
Any ideas?
I managed to solve it myself. I'll post the answer, it may be useful to somebody.
What I thought was right. ctypes checks the folders defined in Windows PATH environment variable and searches them for libraries. Thing is, on Linux the system uses some kind of alias, so when
from ctypes.util import find_library
find_library('portaudio')
it returns the correct portaudio library. But on Windows, only the file names are checked. So, you have to make sure this two conditions are met:
The directory containing the PortAudio DLLs is in your PATH environment variable.
The DLL filename (without the extension) must be exactly 'portaudio'.
About the DLLs, if you were using sounddevice in your Python app, you should be able to find them here:
\your\path\to\python\Lib\site-packages_sounddevice_data\portaudio-binaries
The file is named 'libportaudio64bit.dll', so simply adding that directory to PATH won't do the trick. To overcome this, I just copied the dll into another directory, renamed it as 'portaudio.dll' and added that directory to PATH. Worked like magic.
If you're not using sounddevice, you can also download those same precompiled DLLs from here:
https://github.com/spatialaudio/portaudio-binaries
That's all. Hope it helps!
As the selected answer didn't work for me, because I'm using virtualenv, I put my working solution here.
For me, the working solution is to add _sounddevice_data folder where the .exe file is located then making a portaudio-binaries folder in it and finally putting libportaudio64bit.dll in the recently created folder.
Hope it helps!

Numpy in blender: having a lot of trouble

I'm having a lot of difficulty getting numpy to work in blender. I'm running ubuntu 14.04 and Blender 2.77. I've already tried moving the numpy folder into blender/2.77/scripts/modules. No luck. Here is a screenshot of what I get when I try to import numpy in the python interpreter within blender. Numpy works fine outside of blender. Anyone know how to fix this?
I have that issue on another OS, also it's not just blender and numpy. It comes down to numpy using GCC to compile some parts of it (it uses fortran which prevents the use of clang) which is then linked to some libraries supplied by GCC. When numpy is imported it fails to import a compatible version of these libraries and when an older version is found it fails to load.
The reason this happens is blender first loads the older versions of GCC libraries, then when numpy is loaded the pre-loaded library is used as a matching library by name but fails to match the version needed. There has been some indication that cmake is removing rpath settings during linking that leads to this.
The solution is to get blender to load the newer versions so they match the requirements for numpy. Newer library versions include older version compatibility shims that allow programs built with older versions to work with the newer libraries, so it is usually ok to use a newer library version than the program was compiled with.
First locate the libraries installed by GCC, look for copies of libgcc_s.so libgfortran.so and libquadmath.so. They may be in a path like /usr/local/lib/gcc48 or /opt/local/lib/gcc50
Define the environment variable LD_LIBRARY_PATH to include the path to the newest version before starting blender.
The solution I use is a script containing -
#!/bin/sh
export LD_LIBRARY_PATH=/usr/local/lib/gcc49/
exec /usr/local/bin/blender "$#"
which I run instead of running blender directly.

Error installing Pygame / Python 3.4.1

I'm trying to install Pygame and it returns me the following error "Python version 3.4 required which was not found in the registry". However I already have the Python 3.4.1 installed on my system. Does anyone know how to solve that problem?
I've been using Windows 8.1
Thanks in advance.
Are you using a 64-bit operating system? Try using the 32-bit installer.
Tips I can provide:
Add Python to your Path file in the Advanced settings of your Environmental Variables (just search for it in the control panel)
Something may have gone wrong with the download of Python, so re-install it. Also don't download the 64-bit version, just download the 32-bit version from the main pygame website
Once that's sorted out, transfer the entire Pygame file to the site packages in the Python directory and open up the pygame file and go to this directory in command prompt. Finally, run the Pygame setup from the command prompt which should be something like:
python setup.py
But this will only work if the pygame setup file is called setup.py (it's been a while since I downloaded it), you added Python to the Path file and you're currently in the correct directory in command prompt.
To test if it worked try importing pygame and see if you got an error or not.

How to create a standalone exe using python 3.4

I have created an exe file using cx_freeze (python 3.4).
Along with the exe there is a library.zip,python34.dll and some .pyd file with it.How can i create a standalone exe so that it can be run on other systems where python is not installed.
A single exe file is all i want.Can this be achieved...??
This question was asked previously as well but i didnt find any suitable solutions in it.Help please.
Thanks
At first .pyd files are python native extensions written in either C or C++ for windows target platform. Next in order to get exe built you will going to need to have pyinstaller package installed (http://www.pyinstaller.org/). You can install it using either "pip install pyinstaller", "easy_install pyinstaller" or just specify it as a dependency within REQUIREMENTS.TXT or SETUP.PY of yours. But this package depends on pywin32 package which can only be installed either manually or with easy_install. It doen't support pip because the only bundle that is available is - exe file format. easy_install handles it though.

Resources