tpope / vim-fireplace

fireplace.vim: Clojure REPL support
https://www.vim.org/scripts/script.php?script_id=4978
1.74k stars 139 forks source link

Use correct Python executable on Windows #410

Closed npavlinek closed 1 year ago

npavlinek commented 1 year ago

Starting with Windows 10, Microsoft added Python aliases to the system, meaning you can type either python.exe or python3.exe in a Command Prompt and it'll redirect you to the Microsoft Store to download Python.

When Python is installed on Windows only python.exe is created, there is no python3.exe even if Python 3 was installed, but there's still that Python 3 alias hanging around which causes a problem in the following code:

let g:fireplace_python_executable = executable('python3') ? 'python3' : 'python'

python3.exe will always be found as executable on Windows 10.

Later in the file when this executable is used it of course doesn't work because it's bogus with the following error: Fireplace: Connection Error: Failed to run command python3 .../vim-fireplace/pythonx/fireplace.py

You can set g:fireplace_python_executable in your user .vimrc and get rid of this problem, but I wanted this to just work for people that have no patience for source code spelunking and trying to understand Microsoft logic.

I'm sure this is not the best way to do this. I'd be happy if there's a better way.

tpope commented 1 year ago

I just tried this:

What am I missing?

npavlinek commented 1 year ago

I used the official installer provided at python.org, which only installs python.

I also tried your steps and there are at least two problems:

  1. Microsoft Store installs 64-bit Python. This is a problem because the recommended version of GVim on Windows is 32-bit, therefore a 32-bit Python installation is necessary to use Vim's Python functionality. My assumption is that most people will have the 32-bit version.

gvim

  1. Ignoring the previous problem, the Microsoft Store installer only adds a directory containing Python binaries to the PATH, but Vim needs access to the DLL which is in a different directory, so even if Python is installed Vim can't use it. My assumption here is that most people will install Python from python.org.
tpope commented 1 year ago

Vim's Python functionality has never been less popular. I doubt it shapes nearly as many Python installations as you think it does. Plus even if you do install it from python.org, there's no harm in also installing it from the Microsoft Store, best I can tell.

I think a viable approach that could work is changing the check of executable('python3') to a match against exepath('python3'). When my Windows machine was booted, I noticed that returned a rather specific value for the installation stub that we could probably reject. Show me your exepath('python3') and maybe I can cook something up.

npavlinek commented 1 year ago

Here's the value: C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.18.2691.0_x64__8wekyb3d8bbwe\AppInstallerPythonRedirector.exe. Python is only installed from python.org.