• Re: Correct module for site customization of path

    From Stefan Ram@21:1/5 to Tim Johnson on Fri Nov 1 13:26:44 2024
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dieter.maurer@online.de@21:1/5 to All on Fri Nov 1 17:32:04 2024
    ...
    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

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