Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of $HOME/.local

Tags:

python

pip

I've noticed that I have $HOME/.local on my machine and seems that this directory contains mostly stuff related to python, here is it's full list (it is a bit long).

I would like to ask which action created this directory? I suppose it was pip install --user -r requirements.txt (bellow are commands by which I've figured it out) but I am wondering if there any other tools that stores data here? I suppose if it was pip so easy_install can do this as well or not? Are there any other tools you're aware of that uses this directory or it is pip exclusively?

Following command shows that some python module was imported from this directory, output of last one is here (it is a bit long):

marek@ubuntu:~$ python -c 'import mock; print mock.__file__'
/home/marek/.local/lib/python2.7/site-packages/mock.pyc
marek@ubuntu:~$ echo $PYTHONPATH

marek@ubuntu:~$ tree .local/ | grep  mock
│           ├── mock-1.0.1.egg-info
│           ├── mock.py
│           ├── mock.pyc
│           │   ├── mock.py
│           │   ├── mock.pyc
marek@ubuntu:~$ pip show -f mock
---
Name: mock
Version: 1.0.1
Location: /home/marek/.local/lib/python2.7/site-packages
Requires: 
Files:
Cannot locate installed-files.txt
marek@ubuntu:~$ python -c 'import sys, pprint; pprint.pprint(sys.path)'
['',
 '/home/marek/.local/lib/python2.7/site-packages/nupic-0.3.0.dev0-py2.7-linux-x86_64.egg',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/home/marek/.local/lib/python2.7/site-packages',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.7',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
marek@ubuntu:~$ python -v 2>&1 | tee modules

The following answer says that there should be $HOME/.local/bin/hg in this directory if it was created with pip but I do not have this file. So was it created with pip or not?

like image 665
Wakan Tanka Avatar asked May 16 '15 10:05

Wakan Tanka


People also ask

What is .local folder for?

The Local folder is used to store data that is specific to a single windows system, which means data is not synced between multiple PCs.

Can I delete .local folder?

Removing it will not affect the system as a whole, but it will erase a large amount of user data.

What is .local file in Linux?

The basic file system of Linux operating system is termed as Local file system. It stores any data file as it is in single copy. It stores data files in Tree format. Here, any user can access data files directly.

What is the use of home directory in Linux?

A home directory is the directory or folder commonly given to a user on a network or Unix or Linux variant operating system. With the home directory the user can store all their personal information, files, login scripts, and user information.


2 Answers

It is not directly connected to Python, but Pip uses it. Let's start from the beginning. First you should understand, what the /usr directory is used for:

In current Unices, /usr is where user-land programs and data (as opposed to 'system land' programs and data) are.

It should be used for data installed by the system, i.e. official packages of the distribution.

The /usr/local directory mirrors the structure of the /usr directory, but can be used by system administrators to install local or third party packages for all users.

The ~/.local directory now has the same purpose just for a single user.

Usually you'll install your packages with the default package manager using the /usr directory. But since you're using Pip as package manager for your Python modules, these are installed in ~/.local.

So basically pip might have created ~/.local or just any other programm writing data to one of the directories located there. ~/.local/share for example is used by most applications to store their data.

like image 142
tynn Avatar answered Oct 08 '22 04:10

tynn


$HOME/.local is where user applications place their files and folders in the user's home directory.

According to the Home Directory section of the file-hierarchy(7) man-page, user-specific data should be split among the following sub-directories within $HOME/.local:

  • ~/.local/bin for executables that shall appear in the user's $PATH search path. In Python's case this might be a tool like pipenv.
  • ~/.local/lib for static, private vendor data that is compatible with all architectures. In Python's case these are libraries like requests.
  • ~/.local/share for resources shared between multiple packages. In Python's case this might be the virtualenvs. It is also part of the XDG Base Directory Specification where it is mentioned as the default value of $XDG_DATA_HOME.

From the above observations it should become clear that $HOME/.local has nothing in particular to do with Python itself. pip install --user putting its files into $HOME/.local simply means it is compliant with the recommendations published by freedesktop.org.

If you install packages with sudo pip install, it will distribute the package files according to the Filesystem Hierarchy Standard into the /usr hierarchy instead, which follows the same logic at system-level, just as your distribution's package manager does.

like image 45
Maxim Wandrowski Avatar answered Oct 08 '22 05:10

Maxim Wandrowski