Repository: spack/spack

Issue:
vtk@8.0.1 picks up wrong python version
Trying to install vtk with the `packages.yaml` and Spack version given below results in a CMake-related build-time error.
```bash
$ spack install vtk ^hdf5@1.10.1
...
==> python is already installed in /opt/spack/opt/spack/linux-ubuntu18.04-x86_64/gcc-8/python-3.6.5-35lnfnmcextwomefc5kemft53rouy2kc
...
     3445    [  9%] Generating vtk_compile_complete
     3446    cd /tmp/bassen/spack-stage/spack-stage-fl9jdezj/VTK-8.0.1/spack-build/Wrapping/Python && /usr/bin/python2 /tmp/bassen/spack-stage/spack-stage-fl9jdezj/VTK-8.0.1/spac
             k-build/Wrapping/Python/compile_all_vtk.py
     3447    ImportError: No module named site
...
```
`CMake/FindPythonLibs.cmake` obviously picks up the system installation of Python (`/usr/bin/python2`) instead of the one specified with Spack. CMake needs some help with the `PYTHON_EXECUTABLE`.

The following diff solves the problem:
```bash
$ git diff
diff --git a/var/spack/repos/builtin/packages/vtk/package.py b/var/spack/repos/builtin/packages/vtk/package.py
index e413b4c4e..b7f51abb7 100644
--- a/var/spack/repos/builtin/packages/vtk/package.py
+++ b/var/spack/repos/builtin/packages/vtk/package.py
@@ -24,6 +24,7 @@
 ##############################################################################

 import os
+import sys
 from spack import *


@@ -119,6 +120,7 @@ class Vtk(CMakePackage):
             # Enable/Disable wrappers for Python.
             '-DVTK_WRAP_PYTHON={0}'.format(
                 'ON' if '+python' in spec else 'OFF'),
+            '-DPYTHON_EXECUTABLE={0}'.format(sys.executable),

             # Disable wrappers for other languages.
             '-DVTK_WRAP_JAVA=OFF',
```

---

Spack version:
```bash
$ git describe
v0.8.17-8916-g5be5c486a
```
`packages.yaml`:
```yaml
 packages:
     python:
         version: [3.6.5]
     qt:
         version: [4.8.6]
         variants: +dbus+opengl+phonon+webkit
     py-pyqt:
         version: [4.12.1]
     opengl:
         paths:
             opengl@4.5.0: /opt/opengl/
         buildable: False
     hdf5:
         variants: ~cxx~debug~fortran+hl~mpi+pic+shared+szip+threadsafe
     netcdf:
         variants: ~mpi
     vtk:
         variants: +python+qt
```


Discussion:
@bassenj `sys.executable` will use the executable of the Python used to run Spack, not the Python dependency in the spec. Let me see if I can get something else working.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/vtk/package.py b/var/spack/repos/builtin/packages/vtk/package.py
--- a/var/spack/repos/builtin/packages/vtk/package.py
+++ b/var/spack/repos/builtin/packages/vtk/package.py
@@ -116,15 +116,20 @@ def cmake_args(self):
             '-DNETCDF_C_ROOT={0}'.format(spec['netcdf'].prefix),
             '-DNETCDF_CXX_ROOT={0}'.format(spec['netcdf-cxx'].prefix),
 
-            # Enable/Disable wrappers for Python.
-            '-DVTK_WRAP_PYTHON={0}'.format(
-                'ON' if '+python' in spec else 'OFF'),
-
             # Disable wrappers for other languages.
             '-DVTK_WRAP_JAVA=OFF',
             '-DVTK_WRAP_TCL=OFF',
         ]
 
+        # Enable/Disable wrappers for Python.
+        if '+python' in spec:
+            cmake_args.extend([
+                '-DVTK_WRAP_PYTHON=ON',
+                '-DPYTHON_EXECUTABLE={0}'.format(spec['python'].command.path)
+            ])
+        else:
+            cmake_args.append('-DVTK_WRAP_PYTHON=OFF')
+
         if 'darwin' in spec.architecture:
             cmake_args.extend([
                 '-DCMAKE_MACOSX_RPATH=ON'


Test patch: