Where best to put local modules?

T

tinnews

I'm just beginning to create some python modules for my own use and
I'm wondering where to put them. Initially I have put them in
$HOME/bin and I have set PYTHONPATH to point to them there. It all
seems to be OK but I was wondering if I might be storing up problems
for the future by putting python modules in with my odds and sods of
shell scripts etc. (and with my python 'main' scripts).

Would I be better off putting the modules somewhere else, e.g.
somewhere like $HOME/lib/python?
 
G

Gabriel Genellina

I'm just beginning to create some python modules for my own use and
I'm wondering where to put them. Initially I have put them in
$HOME/bin and I have set PYTHONPATH to point to them there. It all
seems to be OK but I was wondering if I might be storing up problems
for the future by putting python modules in with my odds and sods of
shell scripts etc. (and with my python 'main' scripts).

Would I be better off putting the modules somewhere else, e.g.
somewhere like $HOME/lib/python?

Try lib/pythonX.X/site-packages, which is already on sys.path so you don't
have to set PYTHONPATH
 
B

Bruno Desthuilliers

(e-mail address removed) a écrit :
I'm just beginning to create some python modules for my own use and
I'm wondering where to put them. Initially I have put them in
$HOME/bin and I have set PYTHONPATH to point to them there. It all
seems to be OK but I was wondering if I might be storing up problems
for the future by putting python modules in with my odds and sods of
shell scripts etc. (and with my python 'main' scripts).

Would I be better off putting the modules somewhere else, e.g.
somewhere like $HOME/lib/python?

If you're on a shared system and don't have admin access, this last
solution is probably the best - "pure" modules have nothing to do in a
bin/ directory indeed. Now if it's your own computer, why not just put
them in /path/to/python/libs/site-packages ?
 
T

tinnews

Gabriel Genellina said:
Try lib/pythonX.X/site-packages, which is already on sys.path so you don't
have to set PYTHONPATH
That's fine if it happens to be your own system and you have root
access, however I was actually meaning on a system where I just have a
shell account.
 
T

tinnews

Bruno Desthuilliers said:
(e-mail address removed) a écrit :

If you're on a shared system and don't have admin access, this last
solution is probably the best - "pure" modules have nothing to do in a
bin/ directory indeed. Now if it's your own computer, why not just put
them in /path/to/python/libs/site-packages ?

There's one of each, a system where I have a shell account but not
root access and my home system.

There is a disadvantage of putting stuff in the site-packages directory
isn't there? If/when I upgrade the system the python modules I have added
will effectively not be visible to the upgraded system. I know I can
copy them across to the new site-packages but it's just one more chore
when upgrading. If they were in $HOME/lib/python this issue wouldn't
arise because /home stays the same across upgrades.
 
B

Bruno Desthuilliers

(e-mail address removed) a écrit :
There's one of each, a system where I have a shell account but not
root access and my home system.
There is a disadvantage of putting stuff in the site-packages directory
isn't there? If/when I upgrade the system the python modules I have added
will effectively not be visible to the upgraded system. I know I can
copy them across to the new site-packages but it's just one more chore
when upgrading. If they were in $HOME/lib/python this issue wouldn't
arise because /home stays the same across upgrades.

Yes, true. OTHO, storing modules in your own $HOME/whatever and
modifying your $PYTHONPATH accordingly won't make the modules available
to other accounts. Which may or not be a problem (it happened to be one
for me...).
 
T

tinnews

Bruno Desthuilliers said:
(e-mail address removed) a écrit :

Yes, true. OTHO, storing modules in your own $HOME/whatever and
modifying your $PYTHONPATH accordingly won't make the modules available
to other accounts. Which may or not be a problem (it happened to be one
for me...).

Probably not for me. OK, thanks for all the responses, it seems there
isn't anything of huge consequence that I'm missing so I can just
decide what fits my situation best.
 
Z

Zentrader

Wherever it is physically located, I would suggest linking the dir to /
usr/lib/python/site-python (on a Linux system). AFAIK the sole
purpose of this dir is for the type of thing you are describing. On
my system it also gets copied when Python is updated. What
permissions you give the dir is up to you. Also, you probably want it
somewhere that gets backed up routinely or you may loose your latest
and greatest version if there is a crash, etc..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top