# Ignoring Anaconda Python prefix

**URL:** https://discourse.cmake.org/t/ignoring-anaconda-python-prefix/8831
**Category:** Usage
**Created:** [August 28, 2023, 2:43pm UTC](https://discourse.cmake.org/t/ignoring-anaconda-python-prefix/8831 "2023-08-28T14:43:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [August 28, 2023, 2:43pm UTC](https://discourse.cmake.org/t/ignoring-anaconda-python-prefix/8831/1 "2023-08-28T14:43:07Z")

</div>

My user audience often has Anaconda Python installed with Shared libraries on Path that are not ABI compatible with the desired compiler.

Example: python h5py package needs libhdf5.so to work in Python, but for my compiled programs I can’t use Anaconda libhdf5.so, yet I need Anaconda Python on Path.

This is easily solved by setting in CMakeLists.txt AFTER `find_package(Python)` but before any other `find_package()` calls:

```cmake
# exclude Anaconda directories from search
if(DEFINED ENV{CONDA_PREFIX})
  list(APPEND CMAKE_IGNORE_PREFIX_PATH $ENV{CONDA_PREFIX})
endif()

set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH false)

```

reference:

- [https://cmake.org/cmake/help/latest/variable/CMAKE\_IGNORE\_PREFIX\_PATH.html](https://cmake.org/cmake/help/latest/variable/CMAKE_IGNORE_PREFIX_PATH.html)
- [https://cmake.org/cmake/help/latest/variable/CMAKE\_FIND\_USE\_SYSTEM\_ENVIRONMENT\_PATH.html](https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH.html)

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [October 23, 2023, 2:57pm UTC](https://discourse.cmake.org/t/ignoring-anaconda-python-prefix/8831/2 "2023-10-23T14:57:03Z")

</div>

I have found this preferable to avoid totally ignoring env var PATH:

```auto
# exclude Anaconda directories from search
if(DEFINED ENV{CONDA_PREFIX})
  list(APPEND CMAKE_IGNORE_PREFIX_PATH $ENV{CONDA_PREFIX})
  list(APPEND CMAKE_IGNORE_PATH $ENV{CONDA_PREFIX}/bin)
  # need CMAKE_IGNORE_PATH for CMake < 3.23
  # and to ensure system env var PATH doesn't interfere
  # despite CMAKE_IGNORE_PREFIX_PATH
endif()
```
