What's the difference between dist-packages and site-packages?
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Isolated
--
Chapters
00:00 Question
00:24 Accepted answer (Score 274)
01:38 Answer 2 (Score 10)
02:55 Answer 3 (Score 8)
03:40 Thank you
--
Full question
https://stackoverflow.com/questions/9387...
Accepted answer links:
[Debian Python Wiki]: http://wiki.debian.org/Python
Answer 2 links:
[introduced]: https://lists.ubuntu.com/archives/ubuntu...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pip #easyinstall #packagemanagers
#avk47
ACCEPTED ANSWER
Score 288
dist-packages is a Debian-specific convention that is also present in its derivatives, like Ubuntu. Modules are installed to dist-packages when they come from the Debian package manager into this location:
/usr/lib/python2.7/dist-packages
Since easy_install and pip are installed from the package manager, they also use dist-packages, but they put packages here:
/usr/local/lib/python2.7/dist-packages
From the Debian Python Wiki:
dist-packages instead of site-packages. Third party Python software installed from Debian packages goes into dist-packages, not site-packages. This is to reduce conflict between the system Python, and any from-source Python build you might install manually.
This means that if you manually compile and install Python interpreter from source, it uses the site-packages directory. This allows you to keep the two installations separate, especially since Debian and Ubuntu rely on the system version of Python for many system utilities.
ANSWER 2
Score 14
Debian (and Ubuntu) has introduced its own convention
# python3 -m site
on Ubuntu Focal gives
sys.path = [
'/qpid-dispatch',
'/usr/lib/python38.zip',
'/usr/lib/python3.8',
'/usr/lib/python3.8/lib-dynload',
'/usr/local/lib/python3.8/dist-packages',
'/usr/lib/python3/dist-packages',
]
USER_BASE: '/root/.local' (doesn't exist)
USER_SITE: '/root/.local/lib/python3.8/site-packages' (doesn't exist)
ENABLE_USER_SITE: True
The convention, as described in the linked mailing list, is that python deb packages installed by the distribution package manager go into /usr/lib/python3/dist-packages and packages installed using sudo pip3 go into /usr/local/lib/python3.8/dist-packages.
If you compile and install your own Python interpreter, it will default to placing itself in /usr/local, with /usr/local/bin/pip3 installs going into /usr/local/lib/pythonX.Y/site-packages.
The point of the Debian convention is to keep the three sets of packages separate:
- python packages installed by
apt - packages installed by root user with
/usr/bin/pip3 - packages installed by root user with their own
/usr/local/bin/pip3
ANSWER 3
Score 6
dist-packages is the debian-specific directory where apt and friends install their stuff, and site-packages is the standard pip directory.
The problem is -- what happens when different versions of the same package are present in different directories?
My solution to the problem is to make dist-packages a symlink to site-packages:
for d in $(find $WORKON_HOME -type d -name dist-packages); do
pushd $d
cd ..
if test -d dist-packages/__pycache__; then
mv -v dist-packages/__pycache__/* site-packages/__pycache__/
rmdir -v dist-packages/__pycache__
fi
mv -v dist-packages/* site-packages/
rmdir -v dist-packages
ln -sv site-packages dist-packages
popd
done
(if you are not using gnu tools, remove the -v option).