最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

windows - Python Launcher (py.exe) points to non-existent Python installation in AppData - how to fix? - Stack Overflow

programmeradmin1浏览0评论

When I run py --version on Windows, I get this error:

Unable to create process using '%LOCALAPPDATA%\Programs\Python\Python312\python.exe --version': The system cannot find the file specified.

However, I have Python properly installed in C:\Program Files\Python312\ (confirmed by where python.exe).

Running ftype shows the Python Launcher is installed:

Python.ArchiveFile="C:\Windows\py.exe" "%L" %*
Python.CompiledFile="C:\Windows\py.exe" "%L" %*
Python.File="C:\Windows\py.exe" "%L" %*
Python.NoConArchiveFile="C:\Windows\pyw.exe" "%L" %*
Python.NoConFile="C:\Windows\pyw.exe" "%L" %*

And py -0p --list-paths shows:

 -V:3.12 *        %LOCALAPPDATA%\Programs\Python\Python312\python.exe

The launcher is looking for Python in my AppData folder (probably from an old installation), but Python is actually installed in Program Files. How can I fix this?

When I run py --version on Windows, I get this error:

Unable to create process using '%LOCALAPPDATA%\Programs\Python\Python312\python.exe --version': The system cannot find the file specified.

However, I have Python properly installed in C:\Program Files\Python312\ (confirmed by where python.exe).

Running ftype shows the Python Launcher is installed:

Python.ArchiveFile="C:\Windows\py.exe" "%L" %*
Python.CompiledFile="C:\Windows\py.exe" "%L" %*
Python.File="C:\Windows\py.exe" "%L" %*
Python.NoConArchiveFile="C:\Windows\pyw.exe" "%L" %*
Python.NoConFile="C:\Windows\pyw.exe" "%L" %*

And py -0p --list-paths shows:

 -V:3.12 *        %LOCALAPPDATA%\Programs\Python\Python312\python.exe

The launcher is looking for Python in my AppData folder (probably from an old installation), but Python is actually installed in Program Files. How can I fix this?

Share Improve this question asked Nov 19, 2024 at 11:06 Foad S. FarimaniFoad S. Farimani 14.2k18 gold badges95 silver badges245 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

This issue occurs when Python launcher registration points to an old/removed Python installation. The problem is in the Windows Registry, where Python is registered in both HKEY_CURRENT_USER (user-specific) and HKEY_LOCAL_MACHINE (system-wide) pointing to different locations.

You can verify this by checking both registry locations:

reg query "HKEY_CURRENT_USER\Software\Python\PythonCore" /s
reg query "HKEY_LOCAL_MACHINE\Software\Python\PythonCore" /s

In my case:

  • HKEY_CURRENT_USER pointed to: %LOCALAPPDATA%\Programs\Python\Python312 (non-existent)
  • HKEY_LOCAL_MACHINE pointed to: C:\Program Files\Python312 (correct location)

Solution:

Run these commands in an administrator CMD to remove the incorrect user-specific registration:

reg delete "HKEY_CURRENT_USER\Software\Python\PythonCore\3.12" /f
reg delete "HKEY_CURRENT_USER\Software\Python\PythonCore" /f

After this, the Python launcher will use the correct system-wide registration from HKEY_LOCAL_MACHINE.

Verify the fix:

  1. py --version should now work correctly
  2. py -0p --list-paths should show the Program Files location
  3. reg query "HKEY_CURRENT_USER\Software\Python\PythonCore" /s should find nothing

Why this happens:

This typically occurs when you:

  1. First install Python for the current user only (goes to AppData)
  2. Later uninstall it
  3. Then install Python for all users (goes to Program Files)

The old user-specific registry entries may remain, causing the Python launcher to look in the wrong location.

Alternative Solution:

If you prefer a fresh start, you could:

  1. Uninstall Python completely
  2. Delete any remaining Python folders in AppData
  3. Reinstall Python with:
    • "Install for all users" checked (installs to Program Files)
    • "Add Python to PATH" checked

This will ensure clean registry entries.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论