'Install OpenEXR for python failed

I'm trying to install OpenEXR.

Using :

MacOS 10.14.5

Python 3.6.5

Xcode Version 10.2.1

I tried

pip install openexr

but got the following error:

Collecting openexr
  Using cached https://files.pythonhosted.org/packages/7c/c4/76bf884f59d3137847edf8b93aaf40f6257d8315d0064e8b1a606ad80b1b/OpenEXR-1.3.2.tar.gz
Building wheels for collected packages: openexr
  Building wheel for openexr (setup.py) ... error
  ERROR: Complete output from command /Users/silviojin/anaconda3/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/g9/k_xb1tyd5hbg_48np5hvwh3m0000gn/T/pip-install-0_bh3qoe/openexr/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/g9/k_xb1tyd5hbg_48np5hvwh3m0000gn/T/pip-wheel-gq2luicr --python-tag cp36:
  ERROR: running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.7-x86_64-3.6
  copying Imath.py -> build/lib.macosx-10.7-x86_64-3.6
  running build_ext
  building 'OpenEXR' extension
  creating build/temp.macosx-10.7-x86_64-3.6
  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/silviojin/anaconda3/include -arch x86_64 -I/Users/silviojin/anaconda3/include -arch x86_64 -I/usr/include/OpenEXR -I/usr/local/include/OpenEXR -I/opt/local/include/OpenEXR -I/Users/silviojin/anaconda3/include/python3.6m -c OpenEXR.cpp -o build/temp.macosx-10.7-x86_64-3.6/OpenEXR.o -g -DVERSION="1.3.2"
  warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
  In file included from OpenEXR.cpp:36:
  In file included from /usr/local/include/OpenEXR/ImathBox.h:65:
  In file included from /usr/local/include/OpenEXR/ImathVec.h:46:
  In file included from /usr/local/include/OpenEXR/ImathExc.h:47:
  /usr/local/include/OpenEXR/IexBaseExc.h:49:10: fatal error: 'string' file not found
  #include <string>
           ^~~~~~~~
  1 warning and 1 error generated.
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for openexr
  Running setup.py clean for openexr
Failed to build openexr
Installing collected packages: openexr
  Running setup.py install for openexr ... error
    ERROR: Complete output from command /Users/silviojin/anaconda3/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/g9/k_xb1tyd5hbg_48np5hvwh3m0000gn/T/pip-install-0_bh3qoe/openexr/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/g9/k_xb1tyd5hbg_48np5hvwh3m0000gn/T/pip-record-82it1du_/install-record.txt --single-version-externally-managed --compile:
    ERROR: running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.7-x86_64-3.6
    copying Imath.py -> build/lib.macosx-10.7-x86_64-3.6
    running build_ext
    building 'OpenEXR' extension
    creating build/temp.macosx-10.7-x86_64-3.6
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/silviojin/anaconda3/include -arch x86_64 -I/Users/silviojin/anaconda3/include -arch x86_64 -I/usr/include/OpenEXR -I/usr/local/include/OpenEXR -I/opt/local/include/OpenEXR -I/Users/silviojin/anaconda3/include/python3.6m -c OpenEXR.cpp -o build/temp.macosx-10.7-x86_64-3.6/OpenEXR.o -g -DVERSION="1.3.2"
    warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
    In file included from OpenEXR.cpp:36:
    In file included from /usr/local/include/OpenEXR/ImathBox.h:65:
    In file included from /usr/local/include/OpenEXR/ImathVec.h:46:
    In file included from /usr/local/include/OpenEXR/ImathExc.h:47:
    /usr/local/include/OpenEXR/IexBaseExc.h:49:10: fatal error: 'string' file not found
    #include <string>
             ^~~~~~~~
    1 warning and 1 error generated.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command "/Users/silviojin/anaconda3/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/g9/k_xb1tyd5hbg_48np5hvwh3m0000gn/T/pip-install-0_bh3qoe/openexr/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/g9/k_xb1tyd5hbg_48np5hvwh3m0000gn/T/pip-record-82it1du_/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/g9/k_xb1tyd5hbg_48np5hvwh3m0000gn/T/pip-install-0_bh3qoe/openexr/

same applies if I try to install other packages like:

https://github.com/jamesbowman/openexrpython

or

pip install pyexr

Then I tried:

brew install openexr

and it installed without errors. But I can't be found when importing in python.

Anyone knows why and how to fix this?

Most installation guide recommend installing via pip but I get the error above. The problem seems that it can't find the stdlibc++?



Solution 1:[1]

For me it worked installing OpenEXR via brew first and then directly via git

brew install openexr
pip install git+https://github.com/jamesbowman/openexrpython.git

Solution 2:[2]

This solution worked for me:

Create pip env. Mainly, follow https://www.excamera.com/sphinx/articles-openexr.html

sudo port install openexr

Download source code from https://github.com/jamesbowman/openexrpython

cd openexrpython
sudo python setup.py install
cd ..
pip install ./openexrpython

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Martijn Pieters