view runtime/doc/usr_90.txt @ 32936:c517845bd10e v9.0.1776

patch 9.0.1776: No support for stable Python 3 ABI Commit: https://github.com/vim/vim/commit/c13b3d1350b60b94fe87f0761ea31c0e7fb6ebf3 Author: Yee Cheng Chin <ychin.git@gmail.com> Date: Sun Aug 20 21:18:38 2023 +0200 patch 9.0.1776: No support for stable Python 3 ABI Problem: No support for stable Python 3 ABI Solution: Support Python 3 stable ABI Commits: 1) Support Python 3 stable ABI to allow mixed version interoperatbility Vim currently supports embedding Python for use with plugins, and the "dynamic" linking option allows the user to specify a locally installed version of Python by setting `pythonthreedll`. However, one caveat is that the Python 3 libs are not binary compatible across minor versions, and mixing versions can potentially be dangerous (e.g. let's say Vim was linked against the Python 3.10 SDK, but the user sets `pythonthreedll` to a 3.11 lib). Usually, nothing bad happens, but in theory this could lead to crashes, memory corruption, and other unpredictable behaviors. It's also difficult for the user to tell something is wrong because Vim has no way of reporting what Python 3 version Vim was linked with. For Vim installed via a package manager, this usually isn't an issue because all the dependencies would already be figured out. For prebuilt Vim binaries like MacVim (my motivation for working on this), AppImage, and Win32 installer this could potentially be an issue as usually a single binary is distributed. This is more tricky when a new Python version is released, as there's a chicken-and-egg issue with deciding what Python version to build against and hard to keep in sync when a new Python version just drops and we have a mix of users of different Python versions, and a user just blindly upgrading to a new Python could lead to bad interactions with Vim. Python 3 does have a solution for this problem: stable ABI / limited API (see https://docs.python.org/3/c-api/stable.html). The C SDK limits the API to a set of functions that are promised to be stable across versions. This pull request adds an ifdef config that allows us to turn it on when building Vim. Vim binaries built with this option should be safe to freely link with any Python 3 libraies without having the constraint of having to use the same minor version. Note: Python 2 has no such concept and this doesn't change how Python 2 integration works (not that there is going to be a new version of Python 2 that would cause compatibility issues in the future anyway). --- Technical details: ====== The stable ABI can be accessed when we compile with the Python 3 limited API (by defining `Py_LIMITED_API`). The Python 3 code (in `if_python3.c` and `if_py_both.h`) would now handle this and switch to limited API mode. Without it set, Vim will still use the full API as before so this is an opt-in change. The main difference is that `PyType_Object` is now an opaque struct that we can't directly create "static types" out of, and we have to create type objects as "heap types" instead. This is because the struct is not stable and changes from version to version (e.g. 3.8 added a `tp_vectorcall` field to it). I had to change all the types to be allocated on the heap instead with just a pointer to them. Other functions are also simply missing in limited API, or they are introduced too late (e.g. `PyUnicode_AsUTF8AndSize` in 3.10) to it that we need some other ways to do the same thing, so I had to abstract a few things into macros, and sometimes re-implement functions like `PyObject_NEW`. One caveat is that in limited API, `OutputType` (used for replacing `sys.stdout`) no longer inherits from `PyStdPrinter_Type` which I don't think has any real issue other than minor differences in how they convert to a string and missing a couple functions like `mode()` and `fileno()`. Also fixed an existing bug where `tp_basicsize` was set incorrectly for `BufferObject`, `TabListObject, `WinListObject`. Technically, there could be a small performance drop, there is a little more indirection with accessing type objects, and some APIs like `PyUnicode_AsUTF8AndSize` are missing, but in practice I didn't see any difference, and any well-written Python plugin should try to avoid excessing callbacks to the `vim` module in Python anyway. I only tested limited API mode down to Python 3.7, which seemes to compile and work fine. I haven't tried earlier Python versions. 2) Fix PyIter_Check on older Python vers / type##Ptr unused warning For PyIter_Check, older versions exposed them as either macros (used in full API), or a function (for use in limited API). A previous change exposed PyIter_Check to the dynamic build because Python just moved it to function-only in 3.10 anyway. Because of that, just make sure we always grab the function in dynamic builds in earlier versions since that's what Python eventually did anyway. 3) Move Py_LIMITED_API define to configure script Can now use --with-python-stable-abi flag to customize what stable ABI version to target. Can also use an env var to do so as well. 4) Show +python/dyn-stable in :version, and allow has() feature query Not sure if the "/dyn-stable" suffix would break things, or whether we should do it another way. Or just don't show it in version and rely on has() feature checking. 5) Documentation first draft. Still need to implement v:python3_version 6) Fix PyIter_Check build breaks when compiling against Python 3.8 7) Add CI coverage stable ABI on Linux/Windows / make configurable on Windows This adds configurable options for Windows make files (both MinGW and MSVC). CI will also now exercise both traditional full API and stable ABI for Linux and Windows in the matrix for coverage. Also added a "dynamic" option to Linux matrix as a drive-by change to make other scripting languages like Ruby / Perl testable under both static and dynamic builds. 8) Fix inaccuracy in Windows docs Python's own docs are confusing but you don't actually want to use `python3.dll` for the dynamic linkage. 9) Add generated autoconf file 10) Add v:python3_version support This variable indicates the version of Python3 that Vim was built against (PY_VERSION_HEX), and will be useful to check whether the Python library you are loading in dynamically actually fits it. When built with stable ABI, it will be the limited ABI version instead (`Py_LIMITED_API`), which indicates the minimum version of Python 3 the user should have, rather than the exact match. When stable ABI is used, we won't be exposing PY_VERSION_HEX in this var because it just doesn't seem necessary to do so (the whole point of stable ABI is the promise that it will work across versions), and I don't want to confuse the user with too many variables. Also, cleaned up some documentation, and added help tags. 11) Fix Python 3.7 compat issues Fix a couple issues when using limited API < 3.8 - Crash on exit: In Python 3.7, if a heap-allocated type is destroyed before all instances are, it would cause a crash later. This happens when we destroyed `OptionsType` before calling `Py_Finalize` when using the limited API. To make it worse, later versions changed the semantics and now each instance has a strong reference to its own type and the recommendation has changed to have each instance de-ref its own type and have its type in GC traversal. To avoid dealing with these cross-version variations, we just don't free the heap type. They are static types in non-limited-API anyway and are designed to last through the entirety of the app, and we also don't restart the Python runtime and therefore do not need it to have absolutely 0 leaks. See: - https://docs.python.org/3/whatsnew/3.8.html#changes-in-the-c-api - https://docs.python.org/3/whatsnew/3.9.html#changes-in-the-c-api - PyIter_Check: This function is not provided in limited APIs older than 3.8. Previously I was trying to mock it out using manual PyType_GetSlot() but it was brittle and also does not actually work properly for static types (it will generate a Python error). Just return false. It does mean using limited API < 3.8 is not recommended as you lose the functionality to handle iterators, but from playing with plugins I couldn't find it to be an issue. - Fix loading of PyIter_Check so it will be done when limited API < 3.8. Otherwise loading a 3.7 Python lib will fail even if limited API was specified to use it. 12) Make sure to only load `PyUnicode_AsUTF8AndSize` in needed in limited API We don't use this function unless limited API >= 3.10, but we were loading it regardless. Usually it's ok in Unix-like systems where Python just has a single lib that we load from, but in Windows where there is a separate python3.dll this would not work as the symbol would not have been exposed in this more limited DLL file. This makes it much clearer under what condition is this function needed. closes: #12032 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
author Christian Brabandt <cb@256bit.org>
date Sun, 20 Aug 2023 21:30:04 +0200
parents f8116058ca76
children 93c715c63a4a
line wrap: on
line source

*usr_90.txt*	For Vim version 9.0.  Last change: 2022 May 13

		     VIM USER MANUAL - by Bram Moolenaar

				Installing Vim

								*install*
Before you can use Vim you have to install it.  Depending on your system it's
simple or easy.  This chapter gives a few hints and also explains how
upgrading to a new version is done.

|90.1|	Unix
|90.2|	MS-Windows
|90.3|	Upgrading
|90.4|	Common installation issues
|90.5|	Uninstalling Vim

 Previous chapter: |usr_52.txt|  Write plugins using Vim9 script
Table of contents: |usr_toc.txt|

==============================================================================
*90.1*	Unix

First you have to decide if you are going to install Vim system-wide or for a
single user.  The installation is almost the same, but the directory where Vim
is installed in differs.
   For a system-wide installation the base directory "/usr/local" is often
used.  But this may be different for your system.  Try finding out where other
packages are installed.
   When installing for a single user, you can use your home directory as the
base.  The files will be placed in subdirectories like "bin" and "shared/vim".


FROM A PACKAGE

You can get precompiled binaries for many different UNIX systems.  There is a
long list with links on this page:

	http://www.vim.org/binaries.html ~

Volunteers maintain the binaries, so they are often out of date.  It is a
good idea to compile your own UNIX version from the source.  Also, creating
the editor from the source allows you to control which features are compiled.
This does require a compiler though.

If you have a Linux distribution, the "vi" program is probably a minimal
version of Vim.  It doesn't do syntax highlighting, for example.  Try finding
another Vim package in your distribution, or search on the web site.


FROM SOURCES

To compile and install Vim, you will need the following:

	-  A C compiler (GCC preferred)
	-  The GZIP program (you can get it from www.gnu.org)
	-  The Vim source and runtime archives

To get the Vim archives, look in this file for a mirror near you, this should
provide the fastest download:

	ftp://ftp.vim.org/pub/vim/MIRRORS ~

Or use the home site ftp.vim.org, if you think it's fast enough.  Go to the
"unix" directory and you'll find a list of files there.  The version number is
embedded in the file name.  You will want to get the most recent version.
   You can get the files for Unix in one big archive that contains everything:

	vim-8.2.tar.bz2 ~

You need the bzip2 program to uncompress it.


COMPILING

First create a top directory to work in, for example: >

	mkdir ~/vim
	cd ~/vim

Then unpack the archives there.  You can unpack it like this: >

	tar xf path/vim-8.2.tar.bz2

If your tar command doesn't support bz2 directly: >

	bzip2 -d -c path/vim-8.2.tar.bz2 | tar xf -

Change "path" to where you have downloaded the file.
If you are satisfied with getting the default features, and your environment
is setup properly, you should be able to compile Vim with just this: >

	cd vim82/src
	make

The make program will run configure and compile everything.  Further on we
will explain how to compile with different features.
   If there are errors while compiling, carefully look at the error messages.
There should be a hint about what went wrong.  Hopefully you will be able to
correct it.  You might have to disable some features to make Vim compile.
Look in the Makefile for specific hints for your system.


TESTING

Now you can check if compiling worked OK: >

	make test

This will run a sequence of test scripts to verify that Vim works as expected.
Vim will be started many times and all kinds of text and messages flash by.
If it is alright you will finally see:

	test results: ~
	ALL DONE ~

If you get "TEST FAILURE" some test failed.  If there are one or two messages
about failed tests, Vim might still work, but not perfectly.  If you see a lot
of error messages or Vim doesn't finish until the end, there must be something
wrong.  Either try to find out yourself, or find someone who can solve it.
You could look in the |maillist-archive| for a solution.  If everything else
fails, you could ask in the vim |maillist| if someone can help you.


INSTALLING
							*install-home*
If you want to install in your home directory, edit the Makefile and search
for a line:

	#prefix = $(HOME) ~

Remove the # at the start of the line.
   When installing for the whole system, Vim has most likely already selected
a good installation directory for you.  You can also specify one, see below.
You need to become root for the following.

To install Vim do: >

	make install

That should move all the relevant files to the right place.  Now you can try
running vim to verify that it works.  Use two simple tests to check if Vim can
find its runtime files: >

	:help
	:syntax enable

If this doesn't work, use this command to check where Vim is looking for the
runtime files: >

	:echo $VIMRUNTIME

You can also start Vim with the "-V" argument to see what happens during
startup: >

	vim -V

Don't forget that the user manual assumes you Vim in a certain way.  After
installing Vim, follow the instructions at |not-compatible| to make Vim work
as assumed in this manual.


SELECTING FEATURES

Vim has many ways to select features.  One of the simple ways is to edit the
Makefile.  There are many directions and examples.  Often you can enable or
disable a feature by uncommenting a line.
   An alternative is to run "configure" separately.  This allows you to
specify configuration options manually.  The disadvantage is that you have to
figure out what exactly to type.
   Some of the most interesting configure arguments follow.  These can also be
enabled from the Makefile.

	--prefix={directory}		Top directory where to install Vim.

	--with-features=tiny		Compile with many features disabled.
	--with-features=small		Compile with some features disabled.
	--with-features=big		Compile with more features enabled.
	--with-features=huge		Compile with most features enabled.
					See |+feature-list| for which feature
					is enabled in which case.

	--enable-perlinterp		Enable the Perl interface.  There are
					similar arguments for ruby, python and
					tcl.

	--disable-gui			Do not compile the GUI interface.
	--without-x			Do not compile X-windows features.
					When both of these are used, Vim will
					not connect to the X server, which
					makes startup faster.

To see the whole list use: >

	./configure --help

You can find a bit of explanation for each feature, and links for more
information here: |feature-list|.
   For the adventurous, edit the file "feature.h".  You can also change the
source code yourself!

==============================================================================
*90.2*	MS-Windows

There are two ways to install the Vim program for Microsoft Windows.  You can
uncompress several archives, or use a self-installing big archive.  Most users
with fairly recent computers will prefer the second method.  For the first
one, you will need:

	- An archive with binaries for Vim.
	- The Vim runtime archive.
	- A program to unpack the zip files.

To get the Vim archives, look in this file for a mirror near you, this should
provide the fastest download:

	ftp://ftp.vim.org/pub/vim/MIRRORS ~

Or use the home site ftp.vim.org, if you think it's fast enough.  Go to the
"pc" directory and you'll find a list of files there.  The version number is
embedded in the file name.  You will want to get the most recent version.
We will use "82" here, which is version 8.2.

	gvim82.exe		The self-installing archive.

This is all you need for the second method.  Just launch the executable, and
follow the prompts.

For the first method you must choose one of the binary archives.  These are
available:

	gvim82.zip		The normal MS-Windows GUI version.
	gvim82ole.zip		The MS-Windows GUI version with OLE support.
				Uses more memory, supports interfacing with
				other OLE applications.
	vim82w32.zip		32 bit MS-Windows console version.

You only need one of them.  Although you could install both a GUI and a
console version.  You always need to get the archive with runtime files.

	vim82rt.zip		The runtime files.

Use your un-zip program to unpack the files.  For example, using the "unzip"
program: >

	cd c:\
	unzip path\gvim82.zip
	unzip path\vim82rt.zip

This will unpack the files in the directory "c:\vim\vim82".  If you already
have a "vim" directory somewhere, you will want to move to the directory just
above it.
   Now change to the "vim\vim82" directory and run the install program: >

	install

Carefully look through the messages and select the options you want to use.
If you finally select "do it" the install program will carry out the actions
you selected.
   The install program doesn't move the runtime files.  They remain where you
unpacked them.

In case you are not satisfied with the features included in the supplied
binaries, you could try compiling Vim yourself.  Get the source archive from
the same location as where the binaries are.  You need a compiler for which a
makefile exists.  Microsoft Visual C, MinGW and Cygwin compilers can be used.
Check the file src/INSTALLpc.txt for hints.

==============================================================================
*90.3*	Upgrading

If you are running one version of Vim and want to install another, here is
what to do.


UNIX

When you type "make install" the runtime files will be copied to a directory
which is specific for this version.  Thus they will not overwrite a previous
version.  This makes it possible to use two or more versions next to
each other.
   The executable "vim" will overwrite an older version.  If you don't care
about keeping the old version, running "make install" will work fine.  You can
delete the old runtime files manually.  Just delete the directory with the
version number in it and all files below it.  Example: >

	rm -rf /usr/local/share/vim/vim74

There are normally no changed files below this directory.  If you did change
the "filetype.vim" file, for example, you better merge the changes into the
new version before deleting it.

If you are careful and want to try out the new version for a while before
switching to it, install the new version under another name.  You need to
specify a configure argument.  For example: >

	./configure --with-vim-name=vim8

Before running "make install", you could use "make -n install" to check that
no valuable existing files are overwritten.
   When you finally decide to switch to the new version, all you need to do is
to rename the binary to "vim".  For example: >

	mv /usr/local/bin/vim8 /usr/local/bin/vim


MS-WINDOWS

Upgrading is mostly equal to installing a new version.  Just unpack the files
in the same place as the previous version.  A new directory will be created,
e.g., "vim82", for the files of the new version.  Your runtime files, vimrc
file, viminfo, etc. will be left alone.
   If you want to run the new version next to the old one, you will have to do
some handwork.  Don't run the install program, it will overwrite a few files
of the old version.  Execute the new binaries by specifying the full path.
The program should be able to automatically find the runtime files for the
right version.  However, this won't work if you set the $VIMRUNTIME variable
somewhere.
   If you are satisfied with the upgrade, you can delete the files of the
previous version.  See |90.5|.

==============================================================================
*90.4*	Common installation issues

This section describes some of the common problems that occur when installing
Vim and suggests some solutions.  It also contains answers to many
installation questions.


Q: I Do Not Have Root Privileges.  How Do I Install Vim? (Unix)

Use the following configuration command to install Vim in a directory called
$HOME/vim: >

	./configure --prefix=$HOME

This gives you a personal copy of Vim.  You need to put $HOME/bin in your
path to execute the editor.  Also see |install-home|.


Q: The Colors Are Not Right on My Screen. (Unix)

Check your terminal settings by using the following command in a shell: >

	echo $TERM

If the terminal type listed is not correct, fix it.  For more hints, see
|06.2|.  Another solution is to always use the GUI version of Vim, called
gvim.  This avoids the need for a correct terminal setup.


Q: My Backspace And Delete Keys Don't Work Right

The definition of what key sends what code is very unclear for backspace <BS>
and Delete <Del> keys.  First of all, check your $TERM setting.  If there is
nothing wrong with it, try this: >

	:set t_kb=^V<BS>
	:set t_kD=^V<Del>

In the first line you need to press CTRL-V and then hit the backspace key.
In the second line you need to press CTRL-V and then hit the Delete key.
You can put these lines in your vimrc file, see |05.1|.  A disadvantage is
that it won't work when you use another terminal some day.  Look here for
alternate solutions: |:fixdel|.


Q: I Am Using RedHat Linux.  Can I Use the Vim That Comes with the System?

By default RedHat installs a minimal version of Vim.  Check your RPM packages
for something named "Vim-enhanced-version.rpm" and install that.


Q: How Do I Turn Syntax Coloring On?  How do I make plugins work?

Use the example vimrc script.  You can find an explanation on how to use it
here: |not-compatible|.

See chapter 6 for information about syntax highlighting: |usr_06.txt|.


Q: What Is a Good vimrc File to Use?

See the www.vim.org Web site for several good examples.


Q: Where Do I Find a Good Vim Plugin?

See the Vim-online site: http://vim.sf.net.  Many users have uploaded useful
Vim scripts and plugins there.


Q: Where Do I Find More Tips?

See the Vim-online site: http://vim.sf.net.  There is an archive with hints
from Vim users.  You might also want to search in the |maillist-archive|.

==============================================================================
*90.5*	Uninstalling Vim

In the unlikely event you want to uninstall Vim completely, this is how you do
it.


UNIX

When you installed Vim as a package, check your package manager to find out
how to remove the package again.
   If you installed Vim from sources you can use this command: >

	make uninstall

However, if you have deleted the original files or you used an archive that
someone supplied, you can't do this.  Do delete the files manually, here is an
example for when "/usr/local" was used as the root: >

	rm -rf /usr/local/share/vim/vim82
	rm /usr/local/bin/eview
	rm /usr/local/bin/evim
	rm /usr/local/bin/ex
	rm /usr/local/bin/gview
	rm /usr/local/bin/gvim
	rm /usr/local/bin/gvim
	rm /usr/local/bin/gvimdiff
	rm /usr/local/bin/rgview
	rm /usr/local/bin/rgvim
	rm /usr/local/bin/rview
	rm /usr/local/bin/rvim
	rm /usr/local/bin/rvim
	rm /usr/local/bin/view
	rm /usr/local/bin/vim
	rm /usr/local/bin/vimdiff
	rm /usr/local/bin/vimtutor
	rm /usr/local/bin/xxd
	rm /usr/local/man/man1/eview.1
	rm /usr/local/man/man1/evim.1
	rm /usr/local/man/man1/ex.1
	rm /usr/local/man/man1/gview.1
	rm /usr/local/man/man1/gvim.1
	rm /usr/local/man/man1/gvimdiff.1
	rm /usr/local/man/man1/rgview.1
	rm /usr/local/man/man1/rgvim.1
	rm /usr/local/man/man1/rview.1
	rm /usr/local/man/man1/rvim.1
	rm /usr/local/man/man1/view.1
	rm /usr/local/man/man1/vim.1
	rm /usr/local/man/man1/vimdiff.1
	rm /usr/local/man/man1/vimtutor.1
	rm /usr/local/man/man1/xxd.1


MS-WINDOWS

If you installed Vim with the self-installing archive you can run
the "uninstall-gui" program located in the same directory as the other Vim
programs, e.g. "c:\vim\vim82".  You can also launch it from the Start menu if
installed the Vim entries there.  This will remove most of the files, menu
entries and desktop shortcuts.  Some files may remain however, as they need a
Windows restart before being deleted.
   You will be given the option to remove the whole "vim" directory.  It
probably contains your vimrc file and other runtime files that you created, so
be careful.

Else, if you installed Vim with the zip archives, the preferred way is to use
the "uninstall" program.  You can find it in the same directory as the
"install" program, e.g., "c:\vim\vim82".  This should also work from the usual
"install/remove software" page.
   However, this only removes the registry entries for Vim.  You have to
delete the files yourself.  Simply select the directory "vim\vim82" and delete
it recursively.  There should be no files there that you changed, but you
might want to check that first.
   The "vim" directory probably contains your vimrc file and other runtime
files that you created.  You might want to keep that.

==============================================================================

Table of contents: |usr_toc.txt|

Copyright: see |manual-copyright|  vim:tw=78:ts=8:noet:ft=help:norl: