• Where to put *.pth files for custom Python site packages?

    From Christian Gelinek@21:1/5 to All on Tue Sep 17 03:40:01 2024
    We're using a library of our own Python modules & packages.

    The Python documentation[0] states that the search path can be extended
    via <name>.pth files which should be added to specific directories.
    While the documentation specifically mentions
    "lib/pythonX.Y/site-packages (on Unix and macOS)", I found that Debian
    seems to do this differently:

    $ python -c 'import site ; print(site.getsitepackages())' ['/usr/local/lib/python3.11/dist-packages',
    '/usr/lib/python3/dist-packages', '/usr/lib/python3.11/dist-packages']

    I.e. instead of `site-packages`, it uses `dist-packages` sub-folders.

    Given that these sub-folders are managed by Debian/`apt`, where should I
    place our custom.pth file pointing to other (network drive) folders we
    would like to include in Python's search paths?

    Thanks for your time.

    [0]: https://docs.python.org/3/library/site.html

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From tomas@tuxteam.de@21:1/5 to Christian Gelinek on Tue Sep 17 06:40:01 2024
    On Tue, Sep 17, 2024 at 11:01:00AM +0930, Christian Gelinek wrote:
    We're using a library of our own Python modules & packages.

    The Python documentation[0] states that the search path can be extended via <name>.pth files which should be added to specific directories. While the documentation specifically mentions "lib/pythonX.Y/site-packages (on Unix
    and macOS)", I found that Debian seems to do this differently:

    $ python -c 'import site ; print(site.getsitepackages())' ['/usr/local/lib/python3.11/dist-packages',
    '/usr/lib/python3/dist-packages', '/usr/lib/python3.11/dist-packages']

    I.e. instead of `site-packages`, it uses `dist-packages` sub-folders.

    Given that these sub-folders are managed by Debian/`apt`, where should I place our custom.pth file pointing to other (network drive) folders we would like to include in Python's search paths?

    I think /usr/local is the one for you: the Debian package manager shouldn't touch it. It's at the front to allow you to override the distro's choices.

    This is actually a standard pattern in GNU flavoured Unix-ish environments.

    Cheers
    --
    t

    -----BEGIN PGP SIGNATURE-----

    iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCZukGhAAKCRAFyCz1etHa RltvAJ0dQMNnOCBNeBVJPBdKcHnnJyxY4wCbBtVgj1iTyKCVsW5VXmdCO3aywYU=
    =G6yS
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Florent Rougon@21:1/5 to All on Wed Sep 18 09:50:01 2024
    Hi,

    Le 17/09/2024, Christian Gelinek <cgelinek@radlogic.com.au> a écrit:

    The Python documentation[0] states that the search path can be extended via <name>.pth files which should be added to specific directories.

    (...)

    Given that these sub-folders are managed by Debian/`apt`, where should I place
    our custom.pth file pointing to other (network drive) folders we would like to
    include in Python's search paths?

    You can put .pth files in directories such as

    /usr/local/lib/python3.12/dist-packages

    (substitute the correct Python version). If you use a venv based at <venv-path>, the following directory would also work *for the venv*:

    <venv-path>/lib/python3.12/site-packages

    Alternatively, of course, you can rely on the PYTHONPATH environment
    variable.

    Regards

    --
    Florent

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)