[Tutor] HOWTO: adding to sys.path the simplest way.

Ricardo Aráoz ricaraoz at gmail.com
Fri Aug 24 16:06:03 CEST 2007

Tim Johnson wrote:
> I have a seperate library directory both on my work station on
> the the remote servers that I write applications for..
> I commonly use sys.path.append('/path/to/mylibraries') in my 
> python code.
> That code has to be placed in any standalone script that I write.
> I can also place that path in a system file. On my kubuntu
> workstation, it is /var/lib/python-support/python2.5/.path
> I believe that path is different on the solaris or redhat servers
> that I provide scripts to. Furthermore, any update of the python version
> will necessitate editing of the new .path file.
> I would welcome some opinions on this matter.
> Thanks
> Tim
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

You might put your libraries in your development directory :


Then inside /path/devel/myapplications/mynewapplication/myprogram.py
when you want to access a module you just write :

import mylibraries.mygeneralmodule
from mylibraries.mygeneralmodule import x

import mylibraries.graphiclibraries.mygraphiclibrary
from mylibraries.graphiclibraries.mygraphiclibrary import x

import mylibraries.databaselibraries.mygraphiclibrary
from mylibraries.databaselibraries.mygraphiclibrary import x

Of course /path/devel must be in your path, but as long as the rest of
the structure remains unchanged you may place your stuff anywhere.


More information about the Tutor mailing list