14

I have downloaded the official conda recipe of opencv in AnacondaRecipes.

I have tried to build this package executing:

conda-build recipe -c conda-forge

I am getting the following error when the recipe compiles opencv, when doing [ 72%] Built target opencv_dnn . The error is the following:

[ 67%] Building CXX object modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/grfmt_png.cpp.o
/opt/conda/conda-bld/opencv_1521187259162/work/modules/imgcodecs/src/grfmt_png.cpp:62:10: fatal error: libpng/png.h: No such file or directory
 #include <libpng/png.h>
          ^~~~~~~~~~~~~~
compilation terminated.
modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/build.make:326: recipe for target 'modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/grfmt_png.cpp.o' failed
make[2]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/grfmt_png.cpp.o] Error 1
CMakeFiles/Makefile2:4645: recipe for target 'modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/all' failed
make[1]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

Lookin in the $PREFIX directory, there is not libpng folder, only a libpng16 folder:

/opt/conda/conda-bld/opencv_1521187259162/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeh/include/

I suspect it must be something related to how conda-build manages the path environment, but I do not have any clue of how to solve it.

Environment: conda 4.4.11, OS: Ubuntu 16.04.

UPDATE 23/03/2018

I have also tried:

  • add libpng/png.h to the location pointed by the $PREFIX directory.
  • add /usr/include to the $PATH

No success in either case.

UPDATE 04/03/2018

  • libpng-dev is installed in the environment.

UPDATE 09/04/2018

UPDATE 12/04/2018

merv
  • 67,214
  • 13
  • 180
  • 245
jruizaranguren
  • 12,679
  • 7
  • 55
  • 73
  • What if u put libpng from https://libpng.sourceforge.io/index.html at required location? – Paandittya Mar 22 '18 at 21:10
  • I have updated the question with new tests. Which would you consider is the correct location? – jruizaranguren Mar 23 '18 at 07:37
  • What platform are you using? – Ben Apr 03 '18 at 14:44
  • What do you mean by platform? I get the error both on Ubuntu 16.04 with required dependencies, and in a docker image that I can share in order to reproduce the issue. – jruizaranguren Apr 03 '18 at 18:54
  • Contact build environmentd are in general isolated from the system. You can explicitly set environment variables to include from your session, but others are removed, so setting things in your path should not matter. Have you tried using miniconda3 instead of 2? – ilmarinen Apr 10 '18 at 05:38
  • I meant conda build environments of course.. – ilmarinen Apr 10 '18 at 07:30
  • @ilmarinen, yes I get the same error with miniconda3. – jruizaranguren Apr 10 '18 at 14:03
  • If you build against `conda-forge` packages, you should probably use [conda-forge's recipe](https://github.com/conda-forge/opencv-feedstock). Recipes from anaconda should be used with `defaults` channel. But anyway, **why** are you compiling it on your own? It's precisely the point of `conda` to provide precompiled and compatible binaries... just `conda install -c conda-forge opencv` (or `-c defaults` for the Anaconda version of source) – FabienP Apr 11 '18 at 20:13
  • @FabienP, I need to use a couple of custom options. One of them solves an issue between conda-forge recipe and python multiprocessing. Opencv is so complex and have so many options that it is unlikely that one distribution can fit all scenarios. – jruizaranguren Apr 12 '18 at 07:31

1 Answers1

3

So the issue you have here is that you need the libpng-dev library installed on your OS. Since you mentioned you're operating in a Ubuntu env, you can simply type

sudo apt-get install libpng-dev

Hope this resolves the issue!

UPDATE

Why didn't you try to install opencv with the commands provided in the link:

conda config --add channels conda-forge
conda install opencv
Haris Nadeem
  • 1,322
  • 11
  • 24
  • I forgot to mention that that libpng-dev is indeed installed, both in bare-metal Ubuntu and also in docker image. I update the question accordingly. – jruizaranguren Apr 04 '18 at 06:30
  • So re-visiting the question, I looked into conda forge a bit and found that according to [this](https://conda-forge.org/docs/recipe.html#getting-started#conda-build%20recipe%20-c%20conda-forge) all dependencies have to be in conda forge. So I looked into the website you provided and found that the dependency should be installed exactly where is says it should be [here](https://github.com/AnacondaRecipes/opencv-feedstock/blob/master/recipe/build.sh#L51). So i'll need more details from you on how exactly you are installing the recipe – Haris Nadeem Apr 07 '18 at 20:06
  • I am using `sudo apt-get install libpng-dev`.I will add the docker recipe to reproduce the context next monday. The reason to be interested in a custom adaptation of the récipe is that opencv have a ton of different compilation options, and I need to customize a couple of them. – jruizaranguren Apr 08 '18 at 14:47
  • I updated the question to include the Docker recipe to reproduce the compilation environment. – jruizaranguren Apr 09 '18 at 13:02
  • 1
    Ok, so I read your recipe and think I located the issue. But because my C programming was a little rusty, I opened a few books, read a couple of forum topics and now am quite confident that my hunch is correct. Your issue arises from [here](https://gist.github.com/jruizaranguren/deead8fe2b1865b53f32310397d3e3eb#file-dockerfile-L30). Remove -p /opt/conda from the recipe and run it again. This time it should install for sure. I'll explain the reason in the next comment since I believe i'm running out of space. – Haris Nadeem Apr 12 '18 at 05:43
  • 1
    So the thing is when you run a C program and use `#include ` you are telling the compiler (the preprocessor) that the included header is predefined code to your code. The `<>` tells to search in standard C header location. You can use " " instep of <> which tells first search in our local directory. Thus, we know that the include is searching in the file system. If you type `whereis png.h` you will get either `/usr/include/png.h` or `/usr/local/include/png.h` If you look at the recipe for conda forge it uses `make`. – Haris Nadeem Apr 12 '18 at 05:57
  • 1
    So you need your anaconda installation to be in /usr/local/ since the conda forge uses make. Recall /usr/local is a place to install files built by the administrator, typically by using the make command. The idea is to avoid clashes with files that are part of the operating system, which would either be overwritten or overwrite the local ones otherwise. On the other hand, /opt is a directory for installing unbundled packages (i.e. packages not part of the OS distribution, but provided by an independent source) However,your anaconda is using the OS c library. Thus needs to be in /usr/local – Haris Nadeem Apr 12 '18 at 06:04
  • 1
    Hope that resolves your issue! Btw, here is a [link](https://unix.stackexchange.com/questions/11544/what-is-the-difference-between-opt-and-usr-local) I found that describes the difference between `/opt` and `/usr` much better than I can. jlliagre gives an amazing answer. Please let me know if it works out! (Or if it doesn't work out) Cheers! – Haris Nadeem Apr 12 '18 at 06:06
  • I have added an update including the new recipe with the suggested changes. Unfortunately installing conda in /usr/local/conda makes no difference, and it fails with the same error. – jruizaranguren Apr 12 '18 at 07:51
  • I need some time to think over what the issue is and review the recipe again. To be honest, I was hoping we would have at least raised a different error. – Haris Nadeem Apr 13 '18 at 01:43
  • Till then, could you type `whereis png.h` and share the result? That might give a hint. My belief is that it doesn't exist in `/usr/local/include/libpng/png.h` but instead in `/usr/local/include/png.h` Thus we would need to change the python file installing to `#include `. Is that possible? **NOTE** in my debian machine libdev is installed at `/usr/include/png.h` – Haris Nadeem Apr 13 '18 at 01:45
  • whereis png.h: /usr/include/png.h – jruizaranguren Apr 13 '18 at 11:22
  • I see... So the issue I believe is now to either move `/usr/include/png.h` to `/usr/include/libpng/png.h` or rename the file import in python to `#include – Haris Nadeem Apr 13 '18 at 12:34