Thanks to two additional links, I found not only the intended answer to my question, but also a solution that I like even more, and which, oddly enough, was also explained in my first search result, but was confused by all version- (non) dependent languages โโof site packages.
Answer to the original question: default folder
I wanted to know if there was a canonical (as in the "default") location for my generic packages. And it exists:
>>> import site >>> site.USER_SITE 'C:\\Users\\ojdo\\AppData\\Roaming\\Python\\Python27\\site-packages'
And for an example with Linux and Python 3:
ojdo@ubuntu :~$ python3 >>> import site >>> site.USER_SITE '/home/ojdo/.local/lib/python3.6/site-packages'
The user schema package installation documentation states that the USER_SITE folder - if it exists - will be automatically added to your Python sys.path when the interpreter starts, no manual actions are required.
Bonus: custom catalog for your own packages
- Create a directory anywhere, for example
C:\Users\ojdo\Documents\Python\Libs . - Add the
sitecustomize.py file to the site-packages folder of the Python installation, i.e. in C:\Python27\Lib\site-packages (for all users) or site.USER_SITE (for one user). Then this file is populated with the following code:
import site site.addsitedir(r'C:\Users\ojdo\Documents\Python\Libs')
- Voila, the new directory is now automatically added to
sys.path with every (I) Python session.
How it works: The site package, which is automatically imported every time Python starts up, also tries to import the sitecustomize package for custom changes to the package path. In this case, this dummy package consists of a script that adds the personal package folder to the Python path.
ojdo
source share