# find\_package(Python) fails with "standalone" python

**URL:** https://discourse.cmake.org/t/find-package-python-fails-with-standalone-python/9017
**Category:** Code
**Tags:** os:linux
**Created:** [September 20, 2023, 5:18am UTC](https://discourse.cmake.org/t/find-package-python-fails-with-standalone-python/9017 "2023-09-20T05:18:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![StefanD](https://discourse.cmake.org/user_avatar/discourse.cmake.org/stefand/32/3845_2.png) [@StefanD](https://discourse.cmake.org/u/StefanD)
#### Post date: [September 20, 2023, 5:18am UTC](https://discourse.cmake.org/t/find-package-python-fails-with-standalone-python/9017/1 "2023-09-20T05:18:32Z")

</div>

I am running into issues with finding Python in combination with a “standalone” (static) python. This is a minimal `CMakeLists.txt` I use for testing:

```cmake
cmake_minimum_required(VERSION 3.16)
project(foo)

find_package(Python REQUIRED COMPONENTS Development)

```

In my case I am trying to discover the python unzipped from [this archive](https://github.com/indygreg/python-build-standalone/releases/download/20230826/cpython-3.11.5+20230826-x86_64_v2-unknown-linux-gnu-install_only.tar.gz). The directory structure of the extracted archive is fairly standard. Here is an (abbreviated) directory structure:

```bash
path/to/unzipped/archive
└── python
    ├── bin
    │ ├── python3 -> python3.11
    │ ├── python3.11
    │ ├── ...
    ├── include
    │ └── python3.11
    │ ├── Python.h
    │ └── ...
    ├── lib
    │ ├── libpython3.11.so -> libpython3.11.so.1.0
    │ ├── libpython3.11.so.1.0
    │ ├── libpython3.so
    │ ├── ...
    └── ...

```

I have tried various way to give cmake a hint where to find Python:

- specifying `-D Python3\_ROOT\_DIR=path/to/unzipped/archive/python
- adding `path/to/unzipped/archive/python/bin` to `PATH`
- specifying
  - `Python3_EXECUTABLE=path/to/unzipped/archive/python/bin/python3`,
  - `Python3_LIBRARY=path/to/unzipped/archive/python/lib/libpython3.so`
  - `Python3_INCLUDE_DIR=path/to/unzipped/archive/python/include`

but without success. I always get this error:

```bash
CMake Error at /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Python (missing: Python_INCLUDE_DIRS Python_LIBRARIES
  Development Development.Module Development.Embed)
Call Stack (most recent call first):
  /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.22/Modules/FindPython.cmake:561 (find_package_handle_standard_args)
  CMakeLists.txt:4 (find_package)

```

I can’t really think of a reason why its failing to discover it

My environment:

- cmake version 3.22.1
- Linux jammy 6.2.0-32-generic #32~22.04.1-Ubuntu SMP PREEMPT\_DYNAMIC Fri Aug 18 10:40:13 UTC 2 x86\_64 x86\_64 x86\_64 GNU/Linux

---

<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: [September 20, 2023, 7:28am UTC](https://discourse.cmake.org/t/find-package-python-fails-with-standalone-python/9017/2 "2023-09-20T07:28:29Z")

</div>

You have to use a consistent name between the hints prefix and the package.

Use `Python_` prefix for the hints if you want to use `Python` package. Or use `Python3` package with the hints you have defined.

And be aware that if only `Development` component is specified, the `python3` interpreter is not searched, so that explain why you fail to found the artifacts by adding the python `bin` path to `PATH` environment variable.

---

<div class="post-metadata">

### Author: ![StefanD](https://discourse.cmake.org/user_avatar/discourse.cmake.org/stefand/32/3845_2.png) [@StefanD](https://discourse.cmake.org/u/StefanD)
#### Post date: [September 21, 2023, 12:34am UTC](https://discourse.cmake.org/t/find-package-python-fails-with-standalone-python/9017/3 "2023-09-21T00:34:56Z")

</div>

Ah yes, stupid mistake by me. I guess I got a bit confused looking at both the FindPython and FindPython3 documentation in parallel.

Got it to work now by also adding the `Interpreter` component:

```cmake
cmake_minimum_required(VERSION 3.16)
project(foo)

find_package(Python REQUIRED COMPONENTS Interpreter Development)

```

and then just providing the hint for the python root directory:

```bash
cmake \
-G "Unix Makefiles" \
-B build \
-D Python_ROOT_DIR=/path/to/unzipped/archive/python

```

What maybe also played a role is that I didn’t clear the cmake cache between my many attempts, playing with `FindPython` and `FindPython3` and cmake then doesn’t reattempt to find a certain variable if it already found it before, which lead to surprising behavior (like I removed all my defines but it still knew where to find some of the python components). lesson learned, clear the cache.

(edit: also the interpreter component needs to be added in the find command)
