Whenever I open vim and type :python3 import sys; print(sys.version), it returns python3.8. I want python3 in vim to refer to python3.13. How do I do this? I'm not using NeoVim.
-
1You would need to build vim yourself or install vim version that uses python3.13.Maxim Kim– Maxim Kim2025-05-05 06:23:23 +00:00Commented May 5 at 6:23
-
Do you still have something open in your question? How can we help you further? Otherwise maybe could you accept one of the solutions using the v button next to the arrow voting buttons. It allow the question to rest :-)Vivian De Smedt– Vivian De Smedt ♦2025-05-09 16:37:18 +00:00Commented May 9 at 16:37
3 Answers
Python support in vim comes in 2 flavours (leaving out python2 and python3 differences):
- dynamically linked python library
- statically linked python library
Windows vim executables tend to come with dynamically linked python library so it would be using whatever suitable python version available.
GNU/Linux vim executables usually being built with statically linked python library available for that specific linux distribution. So if your ubuntu or debian has python3 version 3.11 your vim executable would be linked against python3.11 lib.
If you're on linux and want to have vim with a different python lib I would go and build vim using python lib I want to use. It would mean that you would also need to install dev version of that python lib. And the rest tools/libraries needed to build vim.
If you're on windows, you can check :h 'pythonthreedll' for the way to specify other than default python dll.
Reading this together with your previous question Change python version on vim, it looks as if you're trying to do Python development with Vim but somehow fail to call the right version of the Python interpreter. You don't give any context in your question so nobody can possibly know where you go wrong. Also, your problem has most likely been answered on Stack Overflow (which would be a much better place for it).
Using Vim's built-in :python command is the wrong way to run Python code.
It's the Python interface to Vim itself, e.g. when you want to write a Vim plugin in Python.
I recently wrote a more verbose answer on SO to a related question.
It follows that whatever version :python uses doesn't matter at all when developing Python code.
The solution to your greater problem, as already answered by romainl, is that you get the right instance of the Python interpreter in your PATH environment variable.
A rough and simplistic sketch how you could set up a Python project with Vim would be to create a virtual environment (if you don't already use one, you really should):
/path/to/my/python3.13 -m venv my_venv
source my_venv/bin/activate
# now PATH contains /path/to/my/python3.13
vim my_file.py
From inside Vim, you can then issue :!python %:p or :w !python to run your file/buffer with your Python 3.13 interpreter.
-
Still, since 3.8 is EOL, it's reasonable to what the Python interface running plugin code to use an up-to-date Python.D. Ben Knoble– D. Ben Knoble2025-05-05 18:35:38 +00:00Commented May 5 at 18:35
On Windows:
You can determine the version of Python that Vim use by using the :version command and the -DDYNAMIC_PYTHON3_DLL
Past version of Vim links against a fix version of Python.
But recent version of Vim (9.0.1176) link against the python3.dll which will select the first python dll found in the path.
More information with :help python-stable
If you Python 3.13 is installed in C:\Python313 you can achieve that by changing the path environment variable before starting gVim
set path=C:\Python313;%path%
start gVim