-
Notifications
You must be signed in to change notification settings - Fork 626
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
Python3 support #158
Comments
If you don't need python 2.6 support, then both 2.7 and 3 have PyBytes_FromStringAndSize, so you can deal with it wihout cpp macros. |
This is just the first of many errors... I'm not sure all are of that same type |
This is not likely to be a high priority for us since Python3 isn't a factor in the VFX industry yet. (For reference, see www.vfxplatform.com). But if somebody would like to submit a change for Python 3 compatibility that doesn't break 2.7, then that would be very welcome. |
Just curious where the industry is on this now. A year ago, Python 3 support was indeed quite spotty; now, though, the argument's a bit stronger for adopting it. |
Per discussions at the vfxplatform BOF on where the industry is on this now, I think we will see a sudden mass movement when the gilectomy work is done - https://www.youtube.com/watch?v=P3AyI_u66Bw but before then, the incentives to move are probably too low to move quickly on adoption. |
Thanks for the link! Hopefully this won't be another Python 3 with regards to compatibility. For now, for anyone finding this expecting to use Python 3, working with EXRs is possible in Python 3 if you're ok with another dependency. It relies on the Wand library (http://docs.wand-py.org/en/0.4.1/index.html). Get it with So, here's a working color managed solution yielding an appropriate numpy uint array: import numpy as np
import wand, wand.image
#Load an 8 or 16 bit image into an integer array.
with wand.image.Image(filename='something.exr') as img :
#Quick inverse sRGB transform, to undo what Wand does.
img.colorspace = 'srgb'
img.transform_colorspace('rgb')
imgArr = np.fromstring(img.make_blob('RGB'), dtype='uint{}'.format(img.depth)).reshape(img.height, img.width, 3)
#Enjoy your numpy uint array!
#Save your integer array as a wand image.
i = wand.image.Image(blob = imgArr.tostring(), width = np.shape(imgArr)[1], height=np.shape(imgArr)[0], format='RGB')
i.colorspace = 'srgb' #Make sure it saves without a colorspace transformation.
i.save(filename='output.exr') |
It's also possible to use OpenCV (cv2 in python) to read simple OpenEXR files in python3 (even if cv2 need to be build manually from the sources for the moment): import cv2
img = cv2.imread('0001.exr', cv2.IMREAD_UNCHANGED) |
Holy garbage you're right! There's a new pip package that packages OpenCV for Python 3:
Still very much not ideal - for example, I couldn't find any write compression options for EXRs in OpenCV. Hopefully we'll get it natively one day! |
Just spitballing here ~ a community written Pybind11 wrapping could cover Python 2 and 3. It could deliver the same syntax as the official EXR bindings and thus not break any scripts. Pybind11 seems like a good way forward in general since boost::python has been in maintenance mode for some time. https://github.com/pybind/pybind11 |
@meshula I just tried pybind11 for my project (here's the c++ file). It's... magical. There's no better word for it. Making my simple extension was just a matter of an #include, a namespace definition, and a boilerplate function definition for defining the actual Python module.
It does seem better. Take a look at this line:
It would also make support for up to C++14 easy, easy integration with numpy, and more. But, of course, the winning question is... is this be hard to do...? |
Interesting! |
People in the VFX world would certainly like the OpenEXR bindings to support Python 3... I work at the Blender Institute, and I just came here to ask for Py3 support. |
The library installed by Fortunately, the current version of |
About pybind11, I used it to developed my own function to read 1 layer from an exr file to a numpy array, you can take a look at it there: https://github.com/french-paragon/exr-tools/blob/master/pryeadExrChannels/pryeadexrchannels.cpp |
Looking into outstanding issues in OpenEXR issue backlog. openexrpython seems to now support Python3, and technically it's independent of the OpenEXR project anyway. Is there any further work required from OpenEXR itself? OK to close? |
ok to close, our python bindings to IlmBase can be targeted to Python 3. |
Does not work with python3. Pip3 install OpenEXR gives errors like:
The text was updated successfully, but these errors were encountered: