Where to keep local Python modules?

Paul Bryan pbryan at anode.ca
Fri Jul 23 16:04:54 EDT 2021


On my Arch Linux box, slightly different path, but still in .local/bin:

pbryan at dynamo:~$ python3
Python 3.9.6 (default, Jun 30 2021, 10:22:16) 
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python39.zip', '/usr/lib/python3.9', '/usr/lib/python3.9/lib-dynload', '/home/pbryan/.local/lib/python3.9/site-packages', '/usr/lib/python3.9/site-packages']
>>> 


On Fri, 2021-07-23 at 22:46 +0300, Roland Mueller via Python-list
wrote:
> Hello,
> 
> pe 23. heinäk. 2021 klo 21.44 Chris Green (cl at isbd.net) kirjoitti:
> 
> > This isn't a question about how to set PYTHONPATH so that Python
> > code
> > can find imported modules, it's about what is a sensible layout for
> > one's home directory - i.e. where to put Python modules.
> > 
> > I'm running Linux and have a number of Python modules that are only
> > used by my own code.  My top level Python code is all in ~/bin. 
> > I'd
> > prefer to separate the modules so that they don't clutter the name
> > space.
> > 
> > Currently I have my Python modules in a subdirectory of ~/bin and
> > my
> > Python path is set as:-
> > 
> >     PYTHONPATH=/home/chris/bin/pymods
> > 
> > Is this a reasonable approach?  Is there a 'standard' name for the
> > directory containing modules, or a standard place for it?  (I don't
> > mean a system-wide standard place, I mean a 'my' standard place).
> > 
> > Under recent Linux distros there is $HOME/.local/ containing bin
> > and lib
> directories. May be it's ok to use this for user-specific python
> settings
> under Linux.
> 
> E.g. in .bashrc
> export PYTHONPATH=$HOME/.local/python
> 
> Result can be checked then in Python:
> python
> > > > import sys
> > > > sys.path
> ['', '/home/someuser/.local/lib/python', '/usr/lib64/python39.zip',
> '/usr/lib64/python3.9', '/usr/lib64/python3.9/lib-dynload',
> '/usr/local/lib/python3.9/site-packages',
> '/usr/lib64/python3.9/site-packages', '/usr/lib/python3.9/site-
> packages']
> 
> BR,
> Roland
> 
> 
> 
> 
> > 
> > --
> > Chris Green
> > ·
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> > 



More information about the Python-list mailing list