• Correct module for site customization of path

    From Tim Johnson@thjmmj15@gmail.com to comp.lang.python on Thu Oct 31 15:37:44 2024
    From Newsgroup: comp.lang.python

    FYI: I am retired programmer using a recent upgrade to ubuntu 24.04 and
    python 3.12
    My needs are that of a hobbyist at this time. I am on a single user home desktop with root privileges available.

    After the recent upgrades I had to install youtube_dl with pipx for the
    new python version.
    When I ran the script which imported youtube_dl, I got an import error
    as it appears the path to the module
    was not in sys.path. For me,  it was a simple matter of appending the
    path for youtube_dl to sys.path, however,
    I would prefer to not have to do an append at every script using it.

    There is a boatload of documentation of site path configuration, but
    still, I am not sure what option to take.
    Recommendations are invited and welcome.

    Thanks
    --
    Tim
    thjmmj15@gmail.com
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From ram@ram@zedat.fu-berlin.de (Stefan Ram) to comp.lang.python on Fri Nov 1 13:26:44 2024
    From Newsgroup: comp.lang.python

    Tim Johnson <thjmmj15@gmail.com> wrote or quoted:
    There is a boatload of documentation of site path configuration, but
    still, I am not sure what option to take.

    This import situation's got more layers than a Bay Area burrito:

    First off, if you've pip-installed a module like a good little
    dev, you should be golden for importing. No sweat.

    Now, for your homegrown modules, you can make them pip-friendly by
    tossing in the right files and giving them the ol' pip install.

    If you wanna keep tweaking that bad boy, you can go for an
    "editable" install with pip, but lately, they're asking for
    all these extra files now, like you're trying to get a permit
    to build a tiny house in your backyard.

    Some Python versions have this janky workaround where you
    manually create a .pth file in the Lib/site-packages directory
    with the path to your module. Not sure if this flies on Linux,
    but it might be worth taking for a spin since it could be just
    what the doctor ordered for your use case. Fair warning though,
    you'll probably have to rinse and repeat this little dance
    every time you slap a fresh Python version on your rig.

    Of course, you can always expand sys.path at runtime before
    importing, but some libraries (looking at you, mypy) might
    ghost you harder than a Tinder date.

    Then there's relative imports, which let you pull from
    subdirectories (or even parent directories, but only if
    you're working within a package).

    Lastly, there's what I call the "Silicon Valley startup
    office" approach: just throw everything – scripts, modules,
    the kitchen sink – into one directory. It's messy as hell,
    but hey, at least you know where everything is, right?
    No need to fiddle with sys.path or installations.


    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From dieter.maurer@dieter.maurer@online.de to comp.lang.python on Fri Nov 1 17:32:04 2024
    From Newsgroup: comp.lang.python

    ...
    After the recent upgrades I had to install youtube_dl with pipx for the
    new python version.
    When I ran the script which imported youtube_dl, I got an import error
    as it appears the path to the module
    was not in sys.path....
    I see at several options:
    * install `youtoube_dl` where Python looks for it
    (you can print `sys.path` to find out all the places
    normally checked for importable modules)
    * put a (symbolic) link to `youtoube_dl` at a place
    where Python looks for modules
    * use Pythons' `.pth' feature to tell Python additional
    places where to look for modules.
    You can place `.pth` files where Python looks for modules
    to be imported
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Tim Johnson@thjmmj15@gmail.com to comp.lang.python on Fri Nov 1 16:50:12 2024
    From Newsgroup: comp.lang.python

    On 11/1/24 08:32, dieter.maurer@online.de wrote:
    ...
    After the recent upgrades I had to install youtube_dl with pipx for the
    new python version.
    When I ran the script which imported youtube_dl, I got an import error
    as it appears the path to the module
    was not in sys.path....
    I see at several options:

    * install `youtoube_dl` where Python looks for it
    (you can print `sys.path` to find out all the places
    normally checked for importable modules)

    * put a (symbolic) link to `youtoube_dl` at a place
    where Python looks for modules

    * use Pythons' `.pth' feature to tell Python additional
    places where to look for modules.
    You can place `.pth` files where Python looks for modules
    to be imported
    In  /usr/lib/python3.12/sitecustomize.py I put the following:
    import sys
    sys.path.append("path to youtube_dl")
    # In /usr/lib/python3.12/sitecustomize.py
    # Thanks seems to work for me
    cheers
    --
    Tim
    thjmmj15@gmail.com

    --- Synchronet 3.20a-Linux NewsLink 1.114