记录: CMake 找不到Python3的问题处理

版权声明:署名-非商业性使用-相同方式共享

@@ Tags: Windows;CMake;Python38
@@ Date: 2023-06-08 2117

CMake报错:
Could NOT find Python3 (missing: Development Development.Module Development.Embed)

根据如下文件中携带的信息, 发现 FindPython3实际上是通过注册表的方式来获取Python的安装位置:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\share\cmake-3.20\Modules\FindPython3.cmake
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\share\cmake-3.20\Modules\FindPython\Support.cmake

尝试查找如下位置:
HKEY_CURRENT_USER\Software\Python
HKEY_LOCAL_MACHINE\Software\Python\

如果是32位Python, 那么实际位置是这样
HKEY_LOCAL_MACHINE\Software\Wow6432Node\Python\

在注册表编辑器中检查上面的位置, 发现存在一个Python 3.10.11, 但找不到需要的目标版本(3.8.10).

解决方案:

右键导出 (Python 3.10.11) 到本地后, 修改成 Python 3.8.10的版本, 然后导入并删除3.10.11版本目录, 问题解决.

相关附件

注册表相关记录如下:

Python-3.10-32.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Python\PythonCore\3.10-32]
"DisplayName"="Python 3.10 (32-bit)"
"SupportUrl"="https://www.python.org/"
"Version"="3.10.11"
"SysVersion"="3.10"
"SysArchitecture"="32bit"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Python\PythonCore\3.10-32\Help]

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Python\PythonCore\3.10-32\Help\Main Python Documentation]
@="G:\\local\\python\\3.10.11\\Doc\\python31011.chm"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Python\PythonCore\3.10-32\InstalledFeatures]
"exe"="3.10.11150.0"
"dev"="3.10.11150.0"
"lib"="3.10.11150.0"
"doc"="3.10.11150.0"
"tools"="3.10.11150.0"
"pip"="3.10.11150.0"
"core_pdb"="3.10.11150.0"
"core_d"="3.10.11150.0"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Python\PythonCore\3.10-32\InstallPath]
@="G:\\local\\python\\3.10.11\\"
"ExecutablePath"="G:\\local\\python\\3.10.11\\python.exe"
"WindowedExecutablePath"="G:\\local\\python\\3.10.11\\pythonw.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Python\PythonCore\3.10-32\PythonPath]
@="G:\\local\\python\\3.10.11\\Lib\\;G:\\local\\python\\3.10.11\\DLLs\\"

Python-3.8-32.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Python\PythonCore\3.8-32]
"DisplayName"="Python 3.8 (32-bit)"
"SupportUrl"="https://www.python.org/"
"Version"="3.8.10"
"SysVersion"="3.80"
"SysArchitecture"="32bit"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Python\PythonCore\3.8-32\InstalledFeatures]
"exe"="3.8.10150.0"
"dev"="3.8.10150.0"
"lib"="3.8.10150.0"
"doc"="3.8.10150.0"
"tools"="3.8.10150.0"
"pip"="3.8.10150.0"
"core_pdb"="3.8.10150.0"
"core_d"="3.8.10150.0"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Python\PythonCore\3.8-32\InstallPath]
@="G:\\local\\python\\3.8.10\\"
"ExecutablePath"="G:\\local\\python\\3.8.10\\python.exe"
"WindowedExecutablePath"="G:\\local\\python\\3.8.10\\pythonw.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Python\PythonCore\3.8-32\PythonPath]
@="G:\\local\\python\\3.8.10\\Lib\\;G:\\local\\python\\3.8.10\\DLLs\\"