# Error "could not find PythonLibs" when building extension

**URL:** <https://discourse.slicer.org/t/error-could-not-find-pythonlibs-when-building-extension/5336>\
**Category:** Development\
**Tags:** build\
**Created:** [January 11, 2019, 8:19pm UTC](https://discourse.slicer.org/t/error-could-not-find-pythonlibs-when-building-extension/5336 "2019-01-11T20:19:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [January 11, 2019, 8:19pm UTC](https://discourse.slicer.org/t/error-could-not-find-pythonlibs-when-building-extension/5336/1 "2019-01-11T20:19:55Z")

</div>

I’m trying to build SlicerVirtualReality on Windows, but I’m getting this error:

```
3> CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
3> Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)

```

after which I’m getting this error:

```
4> CMake Error at C:/d/S4R/VTK/CMake/vtkModuleAPI.cmake:140 (message):
4> Requested modules not available:
4>
4> vtkRenderingOpenVR
4> Call Stack (most recent call first):
4> C:/d/S4R/VTK-build/VTKConfig.cmake:130 (vtk_module_config)
4> VirtualReality/MRML/CMakeLists.txt:6 (find_package)

```

I’m not sure if they are related, but I have the feeling they are, because I can build other extensions like MarkupsToModel or SlicerRT without problems.

The reason this computer is different from my other computers on which SlicerVirtualReality builds fine is that I installed a Python 3.7 on this one. There was nothing in the environment variables related to that other python installation other than a path, but the error didn’t go away after removing that either.

Does anyone has an idea what to try next? Thanks a lot!

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [January 11, 2019, 8:37pm UTC](https://discourse.slicer.org/t/error-could-not-find-pythonlibs-when-building-extension/5336/2 "2019-01-11T20:37:00Z")

</div>

> [@cpinter](#):
>
> Does anyone has an idea what to try next? Thanks a lot!

It looks like something is resetting the value of `PYTHON_LIBRARY` and `PYTHON_INCLUDE_DIR` CMake cache variable in the extension build tree.

If you add there lines after finding Slicer in [KitwareMedical/SlicerVirtualReality/CMakeLists.txt](https://github.com/KitwareMedical/SlicerVirtualReality/blob/42985c5297e38cac391ff08b3d32bbb583fc8c72/CMakeLists.txt#L23):

```auto
message("PYTHON_LIBRARY :${PYTHON_LIBRARY}")
message("PYTHON_INCLUDE_DIR :${PYTHON_INCLUDE_DIR}")

```

is there value correct ?

If yes, I suggest you do the same in[Rendering/OpenVR/CMakeLists.txt](https://github.com/Slicer/VTK/blob/slicer-v8.2.0-2018-10-02-74d9488523/Rendering/OpenVR/CMakeLists.txt#L10)

That should allow you to find out what is resetting the variables …

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [January 11, 2019, 8:45pm UTC](https://discourse.slicer.org/t/error-could-not-find-pythonlibs-when-building-extension/5336/3 "2019-01-11T20:45:47Z")

</div>

Thanks for the suggestions, @jcfr!

Yes, the variables have the correct values in both the main SlicerVR CmakeLists.txt, and both in the one where the second error occurs (I put it just before line 6):

```
3> PYTHON_LIBRARY :C:/d/S4R/python-install/libs/python27.lib
3> PYTHON_INCLUDE_DIR :C:/d/S4R/python-install/include

```

Rendering/OpenVR/CMakeLists.txt does not give me any output, I guess it never gets that far.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [January 11, 2019, 9:55pm UTC](https://discourse.slicer.org/t/error-could-not-find-pythonlibs-when-building-extension/5336/4 "2019-01-11T21:55:08Z")

</div>

> [@cpinter](#):
>
> CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/FindPackageHandleStandardArgs.cmake:137 (message): 3\> Could NOT find PythonLibs (missing: PYTHON\_LIBRARIES PYTHON\_INCLUDE\_DIRS)

Also what is the full stack, where does the error originate ?

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [January 11, 2019, 9:58pm UTC](https://discourse.slicer.org/t/error-could-not-find-pythonlibs-when-building-extension/5336/5 "2019-01-11T21:58:59Z")

</div>

Here it is:

```
3>------ Build started: Project: VTKRenderingOpenVR, Configuration: Release x64 ------
...
3> CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
3> Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
3> Call Stack (most recent call first):
3> C:/Program Files/CMake/share/cmake-3.12/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
3> C:/d/S4R/VTK/CMake/FindPythonLibs.cmake:213 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
3> C:/d/S4R/VTK/CMake/vtkWrapPython.cmake:167 (find_package)
3> C:/d/S4R/VTK/CMake/vtkInitializeWrapPython.cmake:4 (include)
3> C:/d/S4R/VTK/CMake/vtkExternalModuleMacros.cmake:15 (include)
3> CMakeLists.txt:8 (include)
```

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [January 11, 2019, 10:13pm UTC](https://discourse.slicer.org/t/error-could-not-find-pythonlibs-when-building-extension/5336/6 "2019-01-11T22:13:23Z")

</div>

Then, could you check that the variable are set before the call of `vtkExternalModuleMacros` [here](https://github.com/Slicer/VTK/blob/slicer-v8.2.0-2018-10-02-74d9488523/Rendering/OpenVR/CMakeLists.txt#L8)

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [January 11, 2019, 10:16pm UTC](https://discourse.slicer.org/t/error-could-not-find-pythonlibs-when-building-extension/5336/7 "2019-01-11T22:16:43Z")

</div>

Good point, sorry!

```
2> PYTHON_LIBRARY :PYTHON_LIBRARY-NOTFOUND
2> PYTHON_INCLUDE_DIR :

```

So one says not found, the other one is empty.  
Not sure why it’s not propagated. Thanks!

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [January 11, 2019, 10:22pm UTC](https://discourse.slicer.org/t/error-could-not-find-pythonlibs-when-building-extension/5336/8 "2019-01-11T22:22:55Z")

</div>

Could you try adding:

```auto
-DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY}
-DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR}

```

to [https://github.com/KitwareMedical/SlicerVirtualReality/blob/master/SuperBuild/External\_VTKRenderingOpenVR.cmake#L38](https://github.com/KitwareMedical/SlicerVirtualReality/blob/master/SuperBuild/External_VTKRenderingOpenVR.cmake#L38)

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [February 4, 2019, 4:30pm UTC](https://discourse.slicer.org/t/error-could-not-find-pythonlibs-when-building-extension/5336/9 "2019-02-04T16:30:20Z")

</div>

An update about this:  
I removed all python-related environment variables and paths, which didn’t seem to solve the problem. Then I went on vacation for a few weeks, which involved windows update (and thus restart). Now I’m back and rebased SlicerVR on the master, tried to build, and now it worked. So either the env.var. thing or the update/restart, or both solved it. Thanks for the pointers.
