r/learnpython • u/Candid-Page1895 • 1d ago
Where should I store user created modules?
Good morning,
I use conda environments with pandas for updating product information and data analysis.
I use Windows 11 and Fedora, but am more often using Windows.
I want to start creating and storing my own modules and packages for ease of use on my own machine for private use.
Is there a dedicated storage location for user created modules as there is for say Powershell 7?
I've asked chatgpt and searched google but a lot of the information is conflicting.
Are there dedicated locations and methods of retrieval depending on OS used?
1
u/SleepAffectionate202 1d ago
theres no single default folder you HAVE to use, most people just make a dedicated code directory in their user home folder. if you structure your scripts as a proper package with a pyproject.toml file and do an editable install into your active environment, you can import it from anywhere without messing with system paths.
1
u/Candid-Page1895 1d ago
this is what confused me. I've always thought there would be a specific directory that was added to path so modules could be imported from there.
1
u/Sufficient-Tale6131 1d ago
The reason there isn't one global folder like PowerShell's is that each conda env has its own site-packages. That is the dedicated location, it just changes when you switch environments. With the env activated you can see it with python -c "import site; print(site.getsitepackages())" and the per-user one with python -m site --user-site. If you keep your code in some folder you choose (a repos directory in your home folder is fine on both Windows and Fedora) and do pip install -e . from that folder into the active env, Python will import it from there, so you don't have to copy files into site-packages.
1
u/Candid-Page1895 1d ago
I've read about site-packages and that seems a sensible place. Would it be unusual to keep a folder in windows with all of my modules and packages in and just copy them as needed into any conda env I create? If there are any best practices I'd be happy to follow them, but if copying the directories into site-packages works, then I'm happy to use that method.
1
u/Top-Cauliflower-1808 1d ago
There is no single dedicated folder like PowerShell has. Python uses user site packages but that path changes per OS and per conda environment. The cleaner cross-platform habit is one folder you control added to PYTHONPATH on both Windows and Fedora. For code you edit often use pip install -e . into each environment instead of copying files around.
•
u/OlenaDoubleChecks 51m ago
No official spot like Powershell has. Just put your code in a folder, add a pyproject.toml, and pip install -e. into each conda env. Works the same on Windows and Fedora, and no PYTHONPATH hacks.
1
1
0
0
u/Longjumping-Boss5708 1d ago
You could store them in a dedicated directory on your server. Alternatively, consider a cloud storage solution if you need scalability or remote access.
0
u/AdhesivenessFew8441 22h ago
To answer the part that confused you: there is a folder like that, it is just per environment. Every Python install (and every conda env) has a site-packages folder that is always on sys.path, and if you drop a plain text file ending in .pth in there with one line containing the path to your own folder (for example C:/Users/you/pymods), everything in that folder becomes importable in that env. Run python -c 'import site; print(site.getsitepackages())' inside the env to see where it lives. There is also a per user one (python -m site --user-site), but it is shared by every env with the same Python version, which gets confusing with conda. Long term, the editable install others mentioned is the cleaner version of the same idea and works the same on Windows and Fedora.
6
u/AlexMTBDude 1d ago
Yeah, it's called "Python Packaging" and here are the docs: https://packaging.python.org/en/latest/