Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Last active February 13, 2026 22:00
Show Gist options
  • Select an option

  • Save Konfekt/d487ad78697f334eb8dfaa252fc6fa85 to your computer and use it in GitHub Desktop.

Select an option

Save Konfekt/d487ad78697f334eb8dfaa252fc6fa85 to your computer and use it in GitHub Desktop.
Compile Vim from source with Python 3 support using latest uv-managed Python
#!/usr/bin/env bash
# Compile Vim from source with Python 3 support using uv-managed Python;
# Ensure Vim uses that Python version at runtime by adding its folder to
# PATH by a command such as:
# [ -n "$VIRTUAL_ENV" ] || PATH="$(dirname -- "$(uv python find 3.13)"):$PATH"
# trace exit on error of program or pipe (or use of undeclared variable)
set -o errtrace -o errexit -o pipefail # -o nounset
# optionally debug output by supplying TRACE=1
[[ "${TRACE:-0}" == "1" ]] && set -o xtrace
if [[ "${BASH_VERSINFO:-0}" -gt 4 || ( "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 ) ]]; then
shopt -s inherit_errexit
fi
PS4='+\t '
[[ ! -t 0 ]] && [[ -n "$DBUS_SESSION_BUS_ADDRESS" ]] && command -v notify-send > /dev/null 2>&1 && notify=1
error_handler() {
summary="Error: In ${BASH_SOURCE[0]}, Lines $1 and $2, Command $3 exited with Status $4"
body=$(pr -tn "${BASH_SOURCE[0]}" | tail -n+$(($1 - 3)) | head -n7 | sed '4s/^\s*/>> /')
echo >&2 -en "$summary\n$body"
[ -z "${notify:+x}" ] || notify-send --urgency=critical "$summary" "$body"
exit "$4"
}
trap 'error_handler $LINENO "$BASH_LINENO" "$BASH_COMMAND" $?' ERR
if [[ $# -eq 0 ]] || [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
echo "Compile Vim from source with Python 3 support using uv-managed Python."
echo "Usage: $0"
exit
fi
main() {
# 1. Get the latest/highest uv Python
export MY_PYTHON=$(uv python find 3.13)
# 2. Derive include and lib paths from it (robust, no hard-coding version)
export PYTHON_INCLUDE=$($MY_PYTHON -c 'import sysconfig; print(sysconfig.get_path("include"))')
export PYTHON_LIBDIR=$($MY_PYTHON -c 'import sysconfig; print(sysconfig.get_config_var("LIBDIR"))')
# 3. Set flags (include for headers + lib search + rpath for runtime)
export CFLAGS="-I$PYTHON_INCLUDE"
export LDFLAGS="-L$PYTHON_LIBDIR -Wl,-rpath,$PYTHON_LIBDIR"
# # Also add common deps if you see unresolved symbols later
# export LDFLAGS="$LDFLAGS -ldl -lm -lpthread"
echo "Using Python: $MY_PYTHON"
echo "Include: $PYTHON_INCLUDE"
echo "Lib dir: $PYTHON_LIBDIR"
# 4. Clean previous build
make distclean "-j$(nproc)" 2>/dev/null || true
# 5. Configure (drop --with-python3-config-dir)
./configure \
--with-features=huge \
--enable-multibyte \
--enable-rubyinterp=yes \
--enable-python3interp=yes \
--with-python3-command="$MY_PYTHON" \
--enable-perlinterp=yes \
--enable-gui=gtk2 \
--enable-cscope \
--prefix=/usr/local \
--enable-fail-if-missing
# --enable-luainterp=yes
# 6. Build & install
make VIMRUNTIMEDIR=/usr/local/share/vim/vim91 "-j$(nproc)"
sudo make install PREFIX=/usr/local
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment