FindPython doesn't get the python executable from the virtual environments
Description:
On Linux, when I try to use a Python virtual environment with CMake, FindPython uses the executable from the system path. Is not able to find the Python installation from the virtual environment.
How to reproduce:
I have the following CMakeLists.txt
file:
cmake_minimum_required(VERSION 3.12.2)
project (hello)
find_package(Python3)
CMake version:
➜ cmake --version
cmake version 3.12.20180927-gbe1ce-dirty
CMake suite maintained and supported by Kitware (kitware.com/cmake).
I run this (from /home/israel/cmake_reproducer/test/build
):
python3 -m venv myenv
source myenv/bin/activate
myvenv/bin
:
Content of drwxrwxr-x. 2 israel israel 4096 Sep 28 11:14 .
drwxrwxr-x. 5 israel israel 4096 Sep 28 11:14 ..
-rw-r--r--. 1 israel israel 2223 Sep 28 11:14 activate
-rw-r--r--. 1 israel israel 1279 Sep 28 11:14 activate.csh
-rw-r--r--. 1 israel israel 2443 Sep 28 11:14 activate.fish
-rwxrwxr-x. 1 israel israel 275 Sep 28 11:14 easy_install
-rwxrwxr-x. 1 israel israel 275 Sep 28 11:14 easy_install-3.6
-rwxrwxr-x. 1 israel israel 257 Sep 28 11:14 pip
-rwxrwxr-x. 1 israel israel 257 Sep 28 11:14 pip3
-rwxrwxr-x. 1 israel israel 257 Sep 28 11:14 pip3.6
lrwxrwxrwx. 1 israel israel 7 Sep 28 11:14 python -> python3
lrwxrwxrwx. 1 israel israel 22 Sep 28 11:14 python3 -> /usr/local/bin/python3
Output:
-- The C compiler identification is GNU 8.1.1
-- The CXX compiler identification is GNU 8.1.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python3: /usr/local/bin/python3.6 (found version "3.6.6") found components: Interpreter
-- Configuring done
-- Generating done
-- Build files have been written to: /home/israel/cmake_reproducer/test/build
Expected output:
-- The C compiler identification is GNU 8.1.1
-- The CXX compiler identification is GNU 8.1.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python3: /home/israel/cmake_reproducer/test/build/myvenv/bin/python3.6 (found version "3.6.6") found components: Interpreter
-- Configuring done
-- Generating done
-- Build files have been written to: /home/israel/cmake_reproducer/test/build
Please, let me know if you need more information.