Sujet : Re: Correct module for site customization of path
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.pythonDate : 01. Nov 2024, 14:26:44
Autres entêtes
Organisation : Stefan Ram
Message-ID : <sys.path-20241101141837@ram.dialup.fu-berlin.de>
References : 1
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.