# Python3\_FIND\_STRATEGY missing python3 link

**URL:** https://discourse.cmake.org/t/python3-find-strategy-missing-python3-link/2056
**Category:** Usage
**Created:** [October 23, 2020, 10:16pm UTC](https://discourse.cmake.org/t/python3-find-strategy-missing-python3-link/2056 "2020-10-23T22:16:53Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![gruenich](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/g/977dab/32.png) [@gruenich](https://discourse.cmake.org/u/gruenich)
#### Post date: [October 23, 2020, 10:16pm UTC](https://discourse.cmake.org/t/python3-find-strategy-missing-python3-link/2056/1 "2020-10-23T22:16:54Z")

</div>

FindPython3 offers two strategies: VERSION and LOCATION.

From a user’s point of view, the best strategy would be to check what python3 is referring to. Assume two version of Python are installed (3.6 and 3.7) and 3.6 is the default, i.e, python3 is a link to version 3.6. FindPython3 find with both strategies for one of our users 3.7. When the user want to run a program with python bindings, it crashes, as calling python3 is pointing to 3.6.

Is this intentional? Is there a reason, not to check python3 / /usr/bin/python3 first? In the predecessor of FindPython3, it worked as expected.

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [October 24, 2020, 10:35am UTC](https://discourse.cmake.org/t/python3-find-strategy-missing-python3-link/2056/2 "2020-10-24T10:35:32Z")

</div>

Yes, it is intentional. The strategy is to find the latest version available.

Every developer has a specific need and expect that this need will be the default of the module. As you might expect, this is not possible to have a such behavior.

Now, I agree it is a little problematic to not have an easy way to pick-up the default python interpreter in the PATH. I add this to m TODO list.

In the meantime, you can specify a version to search for or set the variable `Python3_EXECUTABLE` to pick-up the expected interpreter.

---

<div class="post-metadata">

### Author: ![gruenich](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/g/977dab/32.png) [@gruenich](https://discourse.cmake.org/u/gruenich)
#### Post date: [October 28, 2020, 8:50pm UTC](https://discourse.cmake.org/t/python3-find-strategy-missing-python3-link/2056/3 "2020-10-28T20:50:52Z")

</div>

Do you see any workaround which I could include into the CMake code to spare my users from giving an explicit Python version? They mind feel this would be a regression compared to the old behavior before FindPython3.

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [October 30, 2020, 2:46pm UTC](https://discourse.cmake.org/t/python3-find-strategy-missing-python3-link/2056/4 "2020-10-30T14:46:14Z")

</div>

There is no workaround except specifying `Python3_EXECUTABLE`.

But I just submit a [MR](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5448) to solve this problem. In your case, specifying `set(Python3_FIND_GENERIC_NAMES FIRST)` will enable your expected behavior.

---

<div class="post-metadata">

### Author: ![gruenich](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/g/977dab/32.png) [@gruenich](https://discourse.cmake.org/u/gruenich)
#### Post date: [December 11, 2020, 11:54pm UTC](https://discourse.cmake.org/t/python3-find-strategy-missing-python3-link/2056/5 "2020-12-11T23:54:46Z")

</div>

Thank you for fixing my issue in the upcoming CMake version! I just found the time to give it a try. It did not work when I set `Python_FIND_UNVERSIONED_NAMES` but only for `Python3_FIND_UNVERSIONED_NAMES`. Grepping for the generic variable name revealed, that it is never used. Is this a bug or do I misinterpret the documentation?

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [December 12, 2020, 9:33am UTC](https://discourse.cmake.org/t/python3-find-strategy-missing-python3-link/2056/6 "2020-12-12T09:33:41Z")

</div>

I think you misunderstood the usage of variables with prefix `Python`. These variables are not `generic`. They must be used if you use package `FindPython`.

Prefix of variables **must** match with the package name:

- `Python` for `FindPython` package
- `Python2` for `FindPython2` package
- `Python3` for `FindPython3` package

---

<div class="post-metadata">

### Author: ![gruenich](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/g/977dab/32.png) [@gruenich](https://discourse.cmake.org/u/gruenich)
#### Post date: [December 12, 2020, 1:27pm UTC](https://discourse.cmake.org/t/python3-find-strategy-missing-python3-link/2056/7 "2020-12-12T13:27:53Z")

</div>

Ah I see, makes perfectly sense!

I have one more question: Why did you decide to make `LAST` the default. From a user’s point of view, I would expect it to be `FIRST`, because I type into my terminal `python3`, sometimes I don’t even know the exact version but the distribution or my admin does take care that it is a sane default.  
This was also the behavior of `FindPythonInterp`, not sure whether it was intentional or by chance.

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [December 12, 2020, 5:42pm UTC](https://discourse.cmake.org/t/python3-find-strategy-missing-python3-link/2056/8 "2020-12-12T17:42:39Z")

</div>

It is not allowed to change the behavior of any part of `CMake` after publication, so `FIRST` cannot be the default. And, anyway, this initial behavior is fully intentional because it enables the possibility to pick-up the right version when specified as part of `find_package`.

---

<div class="post-metadata">

### Author: ![gruenich](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/g/977dab/32.png) [@gruenich](https://discourse.cmake.org/u/gruenich)
#### Post date: [December 12, 2020, 7:18pm UTC](https://discourse.cmake.org/t/python3-find-strategy-missing-python3-link/2056/9 "2020-12-12T19:18:38Z")

</div>

Ok, makes sense. Thanks for the clarification!
