Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FindPython3 has unexpected behavior on Windows #24692

Closed
tejlmand opened this issue Apr 24, 2020 · 3 comments · Fixed by #25001
Closed

FindPython3 has unexpected behavior on Windows #24692

tejlmand opened this issue Apr 24, 2020 · 3 comments · Fixed by #25001
Assignees
Labels
area: Build System bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug

Comments

@tejlmand
Copy link
Collaborator

Bug created based on: #24364 (comment)
@AdrianEggenberger

I just struggled after an issue that probably is related to this topic. Maybe I may add my observation here. If it would be better to open a new issue give me a note.

The difference in my case is that I'm using a windows system. There are three python instances installed on the system:

  • Python 2.7.x
  • Python 3.8.1 (x86)
  • Python 3.8.2 (x64)

The last of these three is the only one that is in set in the PATH variable. It is also the installation that has west installed and i would prefer to use. Till the update from a previous release to the latest master commit everything worked fine. Since the update an attempt to build with "west build" starts the build process and than fails because west is not found. From the log (see below) I can see that the used Python instance is the one with version 3.8.1 (x86). Why is that? It's quite confusing now...

I think having two python 3 installations is probably not common, but I need both of these because I need to use prebuilt libraries that only works with the (x86) variant.

Is there an elegant way to solve this issue? Can it be solved in the framework?

------ build log -------
C:\Nordic\zephyrproject\zephyr\samples\bluetooth\hci_usb>west build
-- west build: generating a build system
Including boilerplate (Zephyr base (cached)): C:/Nordic/zephyrproject/zephyr/cmake/app/boilerplate.cmake
-- Application: C:/Nordic/zephyrproject/zephyr/samples/bluetooth/hci_usb
-- Zephyr version: 2.2.99 (C:/Nordic/zephyrproject/zephyr)
-- Board: nrf52840dk_nrf52840
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'west'
CMake Error at C:/Nordic/zephyrproject/zephyr/cmake/host-tools.cmake:26 (message):
Unable to import west.version from 'C:/Python38x86/python.exe'
Call Stack (most recent call first):
C:/Nordic/zephyrproject/zephyr/cmake/app/boilerplate.cmake:483 (include)
C:/Nordic/zephyrproject/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
C:/Nordic/zephyrproject/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:40 (include_boilerplate)
CMakeLists.txt:4 (find_package)

Thanks for this very thorough description of your setup.
I will try to see if I can reproduce same behavior.

But to just give you a brief history, then the changed behavior for finding Python is due to switching from having a Zephyr specific backport with local patches of FindPythonInterp.
The FindPythonInterp was deprecated with CMake 3.12, and as there were other issues related to Python location that had to be solved, then it was decided to go for the new FindPython3 CMake module, but as you noticed, it has introduced a new behavior, with some unexpected side-effects.

For a quick test, you can try to set the Windows search Python3_FIND_REGISTRY value to LAST.
https://cmake.org/cmake/help/latest/module/FindPython3.html#hints

but you are also welcome to wait till I have investigated on Windows.

On Windows, CMake FindPython3 will default look into Windows registry, so you can take a look to see if all Python versions installed are correctly registered:
[HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\ or
[HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\

@tejlmand tejlmand added the bug The issue is a bug, or the PR is fixing a bug label Apr 24, 2020
@tejlmand tejlmand self-assigned this Apr 24, 2020
@tejlmand
Copy link
Collaborator Author

@mbolivar-nordic Seems we have a use-case for providing Python used by west directly to CMake here.

@tejlmand tejlmand added priority: medium Medium impact/importance bug area: Build System labels Apr 24, 2020
@AdrianEggenberger
Copy link

I did a short try by adding the following line on top of the CMakeLists.txt:
set(Python3_FIND_REGISTRY "LAST")

This worked and fixed the usage of the wrong python instance. It is fine for me as a temporary workaround.

@tejlmand
Copy link
Collaborator Author

I did a short try by adding the following line on top of the CMakeLists.txt:
set(Python3_FIND_REGISTRY "LAST")

This worked and fixed the usage of the wrong python instance. It is fine for me as a temporary workaround.

Great to hear.
Will still be looking into this, and not blindly change the current code, cause I would like to ensure we don't introduce other side effects by such change.

tejlmand added a commit to tejlmand/zephyr that referenced this issue May 5, 2020
Fixes: zephyrproject-rtos#24692

This commit fixes an issue where FindPython3 could wrongly select the
Python version not in environment path.

If user installed both 32 and 64 bit versions of the same Python, for
example 3.7.x, the current search would only specify that 3.7 is needed.

In some cases, FindPython3 could select the 32 bit version, even if the
64 bit version is the one on %PATH%.

This is fixed, by setting Python3_ROOT_DIR to point to the tested Python
in %PATH%.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
carlescufi pushed a commit that referenced this issue May 13, 2020
Fixes: #24692

This commit fixes an issue where FindPython3 could wrongly select the
Python version not in environment path.

If user installed both 32 and 64 bit versions of the same Python, for
example 3.7.x, the current search would only specify that 3.7 is needed.

In some cases, FindPython3 could select the 32 bit version, even if the
64 bit version is the one on %PATH%.

This is fixed, by setting Python3_ROOT_DIR to point to the tested Python
in %PATH%.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
hakehuang pushed a commit to hakehuang/zephyr that referenced this issue Jun 20, 2020
Fixes: zephyrproject-rtos#24692

This commit fixes an issue where FindPython3 could wrongly select the
Python version not in environment path.

If user installed both 32 and 64 bit versions of the same Python, for
example 3.7.x, the current search would only specify that 3.7 is needed.

In some cases, FindPython3 could select the 32 bit version, even if the
64 bit version is the one on %PATH%.

This is fixed, by setting Python3_ROOT_DIR to point to the tested Python
in %PATH%.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Build System bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants