# FindPython3: how to change the location of python

**URL:** https://discourse.cmake.org/t/findpython3-how-to-change-the-location-of-python/6034
**Category:** Usage
**Created:** [July 8, 2022, 8:54am UTC](https://discourse.cmake.org/t/findpython3-how-to-change-the-location-of-python/6034 "2022-07-08T08:54:09Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [July 8, 2022, 8:54am UTC](https://discourse.cmake.org/t/findpython3-how-to-change-the-location-of-python/6034/1 "2022-07-08T08:54:09Z")

</div>

I am using `find_package(Python3 COMPONENTS Interpreter Development)` to find python, and it can successfully find my conda python.

However, I can not change the location of python. `CMake` find my `conda/envA`, but I want to use `conda/envB`, how can I change the location?

---

<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: [July 8, 2022, 9:56am UTC](https://discourse.cmake.org/t/findpython3-how-to-change-the-location-of-python/6034/2 "2022-07-08T09:56:17Z")

</div>

You must activate the environment you want to use by executing command `conda activate envB`.

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [July 9, 2022, 11:15am UTC](https://discourse.cmake.org/t/findpython3-how-to-change-the-location-of-python/6034/3 "2022-07-09T11:15:57Z")

</div>

But, how can `CMake` find `conda/envB`?

---

<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: [July 9, 2022, 1:26pm UTC](https://discourse.cmake.org/t/findpython3-how-to-change-the-location-of-python/6034/4 "2022-07-09T13:26:00Z")

</div>

When you activate your `conda` environment, environment variable `PATH` is updated accordingly.

Of course, you have to launch a new `CMake` generation from a clean environment (i.e. no `CMakeCache.txt` file in the `build` directory).

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [July 9, 2022, 1:32pm UTC](https://discourse.cmake.org/t/findpython3-how-to-change-the-location-of-python/6034/5 "2022-07-09T13:32:14Z")

</div>

I think it may work for linux?

But, I am working in win10. Even I activate my `conda` environment in a `cmd`, the `CMake-gui` can not find it after I clear all files in `build`.

---

<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: [July 9, 2022, 1:46pm UTC](https://discourse.cmake.org/t/findpython3-how-to-change-the-location-of-python/6034/6 "2022-07-09T13:46:24Z")

</div>

It should work on `Windows`.

But, if you want to edit interactively `Python3` artifacts, you have to specify `Python3_ARTIFACTS_INTERACTIVE` with `ON` value (on the command line or in your CMakeLists.txt), see [Python3 documentation, Artifacts Specification](https://cmake.org/cmake/help/latest/module/FindPython3.html).

But anyway, why do you want to edit the artifacts? Specifying current python through `conda activate` should be enough.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [July 9, 2022, 10:58pm UTC](https://discourse.cmake.org/t/findpython3-how-to-change-the-location-of-python/6034/7 "2022-07-09T22:58:45Z")

</div>

> [@zhang-qiang-github](#):
>
> Even I activate my `conda` environment in a `cmd`, the `CMake-gui` can not find it after I clear all files in `build`.

You would have to launch `cmake-gui` from that `cmd` shell with the conda environment activated for that to work.

---

<div class="post-metadata">

### Author: ![Hameer\_Spire](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hameer_spire/32/2442_2.png) [@Hameer\_Spire](https://discourse.cmake.org/u/Hameer_Spire)
#### Post date: [July 13, 2022, 7:21am UTC](https://discourse.cmake.org/t/findpython3-how-to-change-the-location-of-python/6034/8 "2022-07-13T07:21:20Z")

</div>

Hi! I’m new here, but I’ve been using this for quite a while. You can use `-DPython3_EXECUTABLE={your_python_interpreter_path}` when configuring.
