Skip to content
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

Closed
rggjan opened this issue Jun 2, 2015 · 16 comments
Closed

Python3 support #158

rggjan opened this issue Jun 2, 2015 · 16 comments
Labels
Feature Request A suggested change or addition of functionality to the library.

Comments

@rggjan
Copy link

rggjan commented Jun 2, 2015

Does not work with python3. Pip3 install OpenEXR gives errors like:

OpenEXR.cpp: In function ‘PyObject* channel(PyObject*, PyObject*, PyObject*)’:
OpenEXR.cpp:125:79: error: ‘PyString_FromStringAndSize’ was not declared in this scope
     PyObject *r = PyString_FromStringAndSize(NULL, typeSize * width * height);
@sopvop
Copy link

sopvop commented Jun 2, 2015

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.

@rggjan
Copy link
Author

rggjan commented Jun 2, 2015

This is just the first of many errors... I'm not sure all are of that same type

@ehanway-ilm
Copy link
Contributor

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.

@ehanway-ilm ehanway-ilm added the Feature Request A suggested change or addition of functionality to the library. label Oct 24, 2015
@so-rose
Copy link

so-rose commented Jul 30, 2016

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.

@meshula
Copy link
Contributor

meshula commented Jul 31, 2016

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.

@so-rose
Copy link

so-rose commented Jul 31, 2016

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 sudo pip3 install wand.

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')

@french-paragon
Copy link

french-paragon commented Dec 13, 2016

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) 

@so-rose
Copy link

so-rose commented Dec 14, 2016

Holy garbage you're right! There's a new pip package that packages OpenCV for Python 3:

sudo pip3 install opencv-python will install OpenCV for Python 3 on UNIX systems.

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!

@meshula
Copy link
Contributor

meshula commented Dec 14, 2016

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

@so-rose
Copy link

so-rose commented Jan 25, 2017

@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.

Without comments, the core header files only require ~4K lines of code and depend on Python (2.7 or 3.x, or PyPy2.7 >= 5.7) and the C++ standard library.

It does seem better. Take a look at this line:

Binaries are generally smaller by a factor of at least 2 compared to equivalent bindings generated by Boost.Python. A recent pybind11 conversion of PyRosetta, an enormous Boost.Python binding project, reported a binary size reduction of 5.4x and compile time reduction by 5.8x.

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...?

@meshula
Copy link
Contributor

meshula commented Jan 26, 2017

Interesting!

@sybrenstuvel
Copy link

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.

@adynathos
Copy link

adynathos commented May 19, 2017

The library installed by pip install OpenEXR is actually openexrpython, not this one here.

Fortunately, the current version of openexrpython compiles under Python 3 when built from the repo's master branch.
It is just the PyPI package that is outdated.

@french-paragon
Copy link

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

@cary-ilm cary-ilm added this to the Needs Discussion milestone Jun 29, 2019
@cary-ilm
Copy link
Member

cary-ilm commented Jul 2, 2019

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?

@meshula
Copy link
Contributor

meshula commented Jul 2, 2019

ok to close, our python bindings to IlmBase can be targeted to Python 3.

@meshula meshula closed this as completed Jul 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request A suggested change or addition of functionality to the library.
Projects
None yet
Development

No branches or pull requests

9 participants