# Understanding site-packages directories

**URL:** <https://discuss.python.org/t/understanding-site-packages-directories/12959>\
**Category:** Packaging\
**Created:** [January 7, 2022, 6:28pm UTC](https://discuss.python.org/t/understanding-site-packages-directories/12959 "2022-01-07T18:28:10Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![adamjstewart](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/adamjstewart/32/5608_2.png) [@adamjstewart](https://discuss.python.org/u/adamjstewart)\
**Post date:** [May 20, 2022, 1:28am UTC](https://discuss.python.org/t/understanding-site-packages-directories/12959/17 "2022-05-20T01:28:50Z")

</div>

I think I’ve managed to track down what’s going on here. First of all, the reason that this works with pip is because pip is actually still using distutils, at least for Python 3.9 and older. See [here](https://github.com/pypa/pip/blob/22.1/src/pip/_internal/locations/ __init__.py#L44) where that decision is made. So this explains why pip works and my solution doesn’t.

Pip does basically the same thing that Spack does, and installer is [planning on doing](https://github.com/pypa/installer/pull/103). The main method of interest is [`get_prefixed_libs`](https://github.com/pypa/pip/blob/22.1/src/pip/_internal/locations/ __init__.py#L477), which calls either [`_distutils.get_prefixed_libs`](https://github.com/pypa/pip/blob/22.1/src/pip/_internal/locations/_distutils.py#L165) or [`_sysconfig.get_prefixed_libs`](https://github.com/pypa/pip/blob/22.1/src/pip/_internal/locations/_sysconfig.py#L217) depending on Python version. The `_sysconfig` method queries the `purelib`/`platlib` attributes and replaces `base` and `platbase` with the prefix of interest. However, the `_distutils` method calls [`get_python_lib`](https://github.com/python/cpython/blob/v3.10.4/Lib/distutils/sysconfig.py#L309) which is hard-coded to provide the proper prefix.

The [pip source code](https://github.com/pypa/pip/blob/22.1/src/pip/_internal/locations/ __init__.py#L486) actually alludes to the exact issue I reported above, that the Python shipped with XCode is broken and doesn’t work with sysconfig, so distutils is currently the only way to get this working. I’ll likely try to find a workaround for this in Spack.

---

_[View the full topic](https://discuss.python.org/t/understanding-site-packages-directories/12959)._
