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 ~/.local
:
~/.local/bin
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.
~/.local/lib
Static, private vendor data that is compatible with all architectures.
~/.local/lib/arch-id
Location for placing public dynamic libraries. The architecture
identifier to use is defined on Multiarch Architecture Specifiers
(Tuples) list.
~/.local/share
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-base
and --user-site
options flags. You could use them like so:
user@host:~$ python -m site --user-base
/home/user/.local
user@host:~$ python -m site --user-site
/home/user/.local/lib/python2.7/site-packages
There are several questions posted to StackExchange sites related to the ~/.local
directory which I used as references:
~/.local/bin
directory read PEP 0370 -- Per user site-packages directory. – Piotr Dobrogost Nov 03 '15 at 22:08sudo pip (...)
– see What are the risks of running 'sudo pip'?, Is it acceptable & safe to run pip install under sudo? and Default to --user pip's issue. – Piotr Dobrogost Nov 03 '15 at 22:15