FindPython finds the wrong python executable in Anaconda environment
FindPython seems to be unable to find the proper python executable (i.e. $(which python)) when using an anaconda environment that has a python version lower than the system one. The following was tested on a Ubuntu 20.04 machine (CMake version 3.18.4) and a MacOS laptop (CMake 3.16.4), both using anaconda (python version 3.8.3):
$ conda create --name bug_test python=3.7.9
$ conda activate bug_test
Then the following project was generated with CMake
cmake_minimum_required (VERSION 3.13..3.18)
project(bug_test)
find_package(Python)
This generated the following output:
-- The C compiler identification is Clang 9.0.1
-- The CXX compiler identification is Clang 9.0.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang-9 - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++-9 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python: /home/bnicolet/anaconda3/bin/python3.8 (found version "3.8.3") found components: Interpreter
-- Configuring done
-- Generating done
-- Build files have been written to: /home/bnicolet/Documents/dummy_project/build
As you can see in this line,
-- Found Python: /home/bnicolet/anaconda3/bin/python3.8 (found version "3.8.3") found components: Interpreter
CMake picks up the python from the base environment (i.e. not the bug_test one), the path cmake was expected was:
$ which python
/home/bnicolet/anaconda3/envs/bug_test/bin/python
On another machine (Ubuntu 20.04 running WSL2 and CMake 3.16.3, also tested on version 3.18.4), configuring the same project finds the system python:
-- Found Python: /usr/bin/python3.8 (found version "3.8.2") found components: Interpreter