A directory for binaries and scripts.
It’s shared across Python
versions and the destination directory for scripts.
-
Unix (including Mac)
-
~/.local/bin
-
Windows
-
%APPDATA%/Python/Scripts
On Windows the
Application Data
directory (aka
APPDATA
) was chosen
because it is the most designated place for application data. Microsoft
recommends that software doesn’t write to
USERPROFILE
and
My
Documents
is not suited for application data, either.
The code
doesn’t query the Win32 API, instead it uses the environment variable
%APPDATA%.
The application data directory is part of the roaming profile. In networks
with domain logins the application data may be copied from and to the a
central server. This can slow down log-in and log-off. Users can keep
the data on the server by e.g. setting PYTHONUSERBASE to the value
“%HOMEDRIVE%%HOMEPATH%Applicata Data”. Users should consult their local
administrator for more information.
On Unix
~/.local
was chosen in favor over
~/.python
because the
directory is already used by several other programs in analogy to
/usr/local
.
On Mac OS X Python uses ~/.local directory as well.
Framework builds
of Python include
~/Library/Python/2.6/site-packages
as an additional
search path.
The site module gets a new method
adduserpackage()
which adds the
appropriate directory to the search path. The directory is not added if
it doesn’t exist when Python is started. However the location of the
user site directory and user base directory is stored in an internal
variable for distutils.
The user site directory is added before the system site directories
but after Python’s search paths and
PYTHONPATH
. This setup allows
the user to install a different version of a package than the system
administrator but it prevents the user from accidentally overwriting a
stdlib module. Stdlib modules can still be overwritten with
PYTHONPATH
.
For security reasons the user site directory is
not
added to
sys.path
when the effective user id or group id is not equal to the
process uid / gid
. It’s an additional barrier against code injection
into suid apps. However Python suid scripts
must
always use the -E
and -s option or users can sneak in their own code.
The user site directory can be suppressed with a new option
-s
or
the environment variable
PYTHONNOUSERSITE
. The feature can be
disabled globally by setting
site.ENABLE_USER_SITE
to the value
False
. It must be set by editing
site.py
. It can’t be altered
in
sitecustomize.py
or later.
The path to the user base directory can be overwritten with the
environment variable
PYTHONUSERBASE
. The default location is used
when
PYTHONUSERBASE
is not set or empty.
distutils.command.install
(setup.py install) gets a new argument
--user
to install packages in the user site directory. The required
directories are created on demand.
distutils.command.build_ext
(setup.py build_ext) gets a new argument
--user
which adds the include/ and lib/ directories in the user base
directory to the search paths for header files and libraries. It also
adds the lib/ directory to rpath.
The
site
module gets two arguments
--user-base
and
--user-site
to print the path to the user base or user site directory to the standard
output. The feature is intended for scripting, e.g.
./configure
--prefix
$(python2.5
-m
site
--user-base)
distutils.sysconfig
will get methods to access the private variables
of site. (not yet implemented)
The Windows updater needs to be updated, too. It should create a menu
item which opens the user site directory in a new explorer windows.
A reference implementation is available in the bug tracker.
This document has been placed in the public domain.
-
[
1
]
-
Virtual Python
http://peak.telecommunity.com/DevCenter/EasyInstall#creating-a-virtual-python
-
[
2
]
-
Working Env
https://pypi.org/project/workingenv.py/
https://ianbicking.org/archive/workingenv-revisited.html
-
[
3
]
-
Virtual Env
https://pypi.org/project/virtualenv/
-
[
4
]
-
reference implementation
https://github.com/python/cpython/issues/46132
http://svn.python.org/view/sandbox/trunk/pep370
-
[
5
]
-
MSDN: CSIDL
https://learn.microsoft.com/en/windows/win32/shell/csidl
[6] Initial suggestion for a per user site-packages directory
https://mail.python.org/archives/list/[email protected]/message/V23CUKRH3VCHFLV33ADMHJSM53STPA7I/
-
[
7
]
-
Suggestion of ~/.local/
https://mail.python.org/pipermail/python-dev/2008-January/075985.html
-
[
8
]
-
APPDATA discussion
https://mail.python.org/pipermail/python-dev/2008-January/075993.html
-
[
9
]
-
Security concerns and -s option
https://mail.python.org/pipermail/python-dev/2008-January/076130.html
-
[
10
]
-
Discussion about the bin directory
https://mail.python.org/pipermail/python-dev/2008-January/076162.html
-
[
11
]
-
freedesktop.org XGD basedir specs mentions ~/.local
https://www.freedesktop.org/wiki/Specifications/basedir-spec/
-
[
12
]
-
~/.local for Mac and usercustomize file
https://mail.python.org/pipermail/python-dev/2008-January/076236.html
-
[
13
]
-
Roaming profile on Windows
https://mail.python.org/pipermail/python-dev/2008-January/076256.html