Path: ...!fu-berlin.de!uni-berlin.de!not-for-mail From: ram@zedat.fu-berlin.de (Stefan Ram) Newsgroups: comp.lang.python Subject: Re: Correct module for site customization of path Date: 1 Nov 2024 13:26:44 GMT Organization: Stefan Ram Lines: 40 Expires: 1 Jul 2025 11:59:58 GMT Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de NiKV7X27VWyuK8616FaRZQTA4LYr15TFp4LeOSNF2M1zZC Cancel-Lock: sha1:jlg1XlbmuHvQglIbknMb7jhXEI8= sha256:f9X0TDdrjzGuaHbDEMmpXOruswABgdTjCszbu8tjYMM= X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved. Distribution through any means other than regular usenet channels is forbidden. It is forbidden to publish this article in the Web, to change URIs of this article into links, and to transfer the body without this notice, but quotations of parts in other Usenet posts are allowed. X-No-Archive: Yes Archive: no X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some services to mirror the article in the web. But the article may be kept on a Usenet archive server with only NNTP access. X-No-Html: yes Content-Language: en-US Bytes: 3181 Tim Johnson 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.