cmake doesn't use the anaconda environment python interpreter I've specified, why?

2 views
Skip to first unread message

hinoki...@gmail.com

unread,
Jan 15, 2017, 11:10:01 PM1/15/17
to Anaconda - Public
Here is the situation.
I'm compiling opencv in a dedicated anaconda environment, called opencv3.

The cmake options I have specified for python are:

-DPYTHON_LIBRARY=PATH2ANACONDA/envs/opencv3/lib/libpython3.5.so
-DPYTHON_INCLUDE_DIR=PATH2ANACONDA/envs/opencv3/include/python3.5m
-DPYTHON_EXECUTABLE=PATH2ANACONDA/envs/opencv3/bin/python3.5
-DPYTHON_PACKAGES_PATH=PATH2ANACONDA/envs/opencv3/lib/python3.5/site-packages

Yet, cmake throws the following intriguing 3 lines:

-- Found PythonInterp: /home/ludovic/anaconda3/envs/opencv3/bin/python3.5 (found suitable version "3.5.2", minimum required is "2.7")
-- Found PythonInterp: /usr/bin/python3.4 (found suitable version "3.4.3", minimum required is "3.4")
-- Could NOT find PythonLibs: Found unsuitable version "3.5.2", but required is exact version "3.4.3" (found /home/ludovic/anaconda3/envs/opencv3/lib/libpython3.5.so)

This says that the python interpreter I have specified is first correctly located, but then the system wide python is used as is the python library.

And cmake then tells me:
--   Python 3:
--     Interpreter:                 /usr/bin/python3.4 (ver 3.4.3)
--
--   Python (for build):            /usr/bin/python3.4

Why is cmake not using the one I have specified?
Is there another cmake option I should specify?

cmake reference:
https://cmake.org/cmake/help/v3.0/module/FindPythonLibs.html

Ludovic

Michael Sarahan

unread,
Jan 15, 2017, 11:33:51 PM1/15/17
to Anaconda - Public
Are you starting from the conda-forge recipe?  https://github.com/conda-forge/opencv-feedstock/blob/master/recipe/

This is probably the best reference recipe around.  Many people have collaboratively created and revised this recipe.  Give this a shot with conda-build, and hopefully you'll have better luck.

--
Anaconda Community Support Group Brought to you by Continuum Analytics
---
You received this message because you are subscribed to the Google Groups "Anaconda - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to anaconda+unsubscribe@continuum.io.
To post to this group, send email to anac...@continuum.io.
Visit this group at https://groups.google.com/a/continuum.io/group/anaconda/.

Message has been deleted

hinoki...@gmail.com

unread,
Jan 16, 2017, 1:02:07 AM1/16/17
to Anaconda - Public
Are you starting from the conda-forge recipe?  https://github.com/conda-forge/opencv-feedstock/blob/master/recipe/

No Michael. I started from the pyimagesearch info on compiling opencv for a virtualenv with pip, and I adapted it to a conda environment:
http://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/
But thanks for the link anyway.
(And I forgot to mention I am under linux ubuntu 14.04)

I have just found this hint:
http://stackoverflow.com/a/17324494/6358973
A comment explains: "For python3 you want to do PYTHON3_[PACKAGES|LIBRARY] etc"
It's not obvious what the "etc" above refers to, so after trying replacing all PYTHON_ with PYTHON3_ and testing the output of cmake, it came out that the following seems to be the way:

-DPYTHON3_PACKAGES_PATH=/home/ludovic/anaconda3/envs/opencv3/lib/python3.5/site-packages
-DPYTHON3_LIBRARY=/home/ludovic/anaconda3/envs/opencv3/lib/libpython3.5.so
-DPYTHON_INCLUDE_DIR=/home/ludovic/anaconda3/envs/opencv3/include/python3.5m
-DPYTHON3_EXECUTABLE=/home/ludovic/anaconda3/envs/opencv3/bin/python3.5
-DPYTHON_NUMPY_INCLUDE_DIRS=/home/ludovic/anaconda3/envs/opencv3/lib/python3.5/site-packages/numpy/core/include

Which gave me:
[...]
-- Found PythonInterp: /usr/bin/python2.7 (found suitable version "2.7.6", minimum required is "2.7")
-- Could NOT find PythonLibs: Found unsuitable version "3.5.2", but required is exact version "2.7.6" (found /usr/lib/x86_64-linux-gnu/libpython2.7.so)
-- Found PythonInterp: /home/ludovic/anaconda3/envs/opencv3/bin/python3.5 (found suitable version "3.5.2", minimum required is "3.4")
-- Found PythonLibs: /home/ludovic/anaconda3/envs/opencv3/lib/libpython3.5.so (found suitable exact version "3.5.2")
[...]

and then, cmake's conclusion is:

[...]
--   Python 2:
--     Interpreter:                 /usr/bin/python2.7 (ver 2.7.6)
--   Python 3:
--     Interpreter:                 /home/ludovic/anaconda3/envs/opencv3/bin/python3.5 (ver 3.5.2)
--     Libraries:                   /home/ludovic/anaconda3/envs/opencv3/lib/libpython3.5.so (ver 3.5.2)
--     numpy:                       /home/ludovic/anaconda3/envs/opencv3/lib/python3.5/site-packages/numpy/core/include (ver 1.11.3)
--     packages path:               /home/ludovic/anaconda3/envs/opencv3/lib/python3.5/site-packages
--   Python (for build):            /usr/bin/python2.7
[...]

So it seems cmake searches by default both versions of python, and with the way I set the options in cmake, it uses the one I specified for python 3.
I don't understand what is the "Python (for build)" used for, and if anything is really built with python, nor why a python 2 interpreter seems to be set by default by the opencv cmake.

But at least now, with this cmake setting followed by make and make install I now have opencv installed in my specific "opencv3" anaconda environment.
import cv2 works fine and I can run some of the samples.

Ludovic

RedDevil91

unread,
Jan 16, 2017, 5:04:48 AM1/16/17
to Anaconda - Public, hinoki...@gmail.com
I had the same issue when I was trying to build opencv for a conda environment. After 3 days of trying I gave up and tried something else.
Accidentally I have found an openCV package which works fine (even VideoCapture is working!).

the link:

nites...@gmail.com

unread,
Sep 27, 2017, 10:40:30 AM9/27/17
to Anaconda - Public, hinoki...@gmail.com
You solved a huge mystery!
Thanks a ton.
Reply all
Reply to author
Forward
0 new messages