The short answer is that
~/.local/bin is the default value of Python's User Script Directory and that
pip may install executables into this directory if it performs a user-local installation. It may also install files into other subdirectories of
~/.local, which is the default value of the User Base Directory. More details below.
I'm not sure if this is its earliest introduction, but the
~/.local directory appears in the file-system hierarchy specification of the systemd init system, where it defines several subdirectories of
Executables that shall appear in the user's $PATH search path. It is
recommended not to place executables in this directory that are not
useful for invocation from a shell; these should be placed in a
subdirectory of ~/.local/lib instead. Care should be taken when
placing architecture-dependent binaries in this place, which might be
problematic if the home directory is shared between multiple hosts
with different architectures.
Static, private vendor data that is compatible with all architectures.
Location for placing public dynamic libraries. The architecture
identifier to use is defined on Multiarch Architecture Specifiers
Resources shared between multiple packages, such as fonts or artwork.
Usually, the precise location and format of files stored below this
directory is subject to specifications that ensure interoperability.
If an application finds $XDG_DATA_HOME set, it should use the
directory specified in it instead of this directory.
The adoption of the
~/.local directory by Python appears to have been introduced in Python 2.6 and is documented in PEP (Python Enhancement Proposal) 370:
The specification includes the following definitions for Unix systems (including Mac OS X).
From this we can conclude that Python has the concept of a so-called "Base User Directory" and that its default value is
~/.local. The Base User Directory is discussed in the Python documentation for the
site module. In particular, it provides methods for determining the values of your User Base Directory and User Site Directory, the
--user-site options flags. You could use them like so:
user@host:~$ python -m site --user-base
user@host:~$ python -m site --user-site
There are several questions posted to StackExchange sites related to the
~/.local directory which I used as references: