How do I add permanently to Pythons sys.path?
Aaron "Castironpi" Brady
castironpi at gmail.com
Tue Sep 16 17:33:09 EDT 2008
On Sep 16, 4:24 pm, cnb <circularf... at yahoo.se> wrote:
> On Sep 16, 10:53 pm, "Aaron \"Castironpi\" Brady"
>
>
>
> <castiro... at gmail.com> wrote:
> > On Sep 16, 3:16 pm, cnb <circularf... at yahoo.se> wrote:
>
> > > On Sep 16, 7:49 pm, "Aaron \"Castironpi\" Brady"
> > > > > Now I have my personal programs in C:/Python25/Progs/
>
> > > > > How do I add so that I can just do "import somefile" from anywhere in
> > > > > that directory in the interpreter and it can load files from other
> > > > > folders in that directory.
>
> > > > Add a file: \Lib\site-packages\locals.pth
>
> > > > with contents, path to the directory you want to add (/python25/progs/)
>
> > > And we have a winner!
>
> > > Now it works. Both doing import and loading form fiel with C-c C-l
>
> > > However jsut including C:/Python/Progs wasn't enough. I had to add the
> > > folder inside that that contains the files i needed.
>
> > > so how do i add all files within progs? is there something like C:/
> > > python25/progs/* ?
>
> > You have:
>
> > c:/python/progs/abc/filea.py
> > c:/python/progs/abc/fileb.py
> > c:/python/progs/def/filed.py
> > c:/python/progs/def/filee.py
>
> > __init__.py in progs (empty...)
> > __init__.py in abc
> > __init__.py in def
>
> > c:/python/site-packages/lib/locals.py which contains:
> > c:/python/progs/
>
> > You don't need the subdirectories. You can do:
>
> > import abc
> > import abc.filea
> > from abc import filea
>
> no I can't...
Ok well here's mine:
I have
/Documents and Settings/usr/Desktop/working/imptest/
in locals.pth. These directories:
Directory of C:\Documents and Settings\usr\Desktop\working\imptest
09/16/2008 04:29 PM <DIR> impt
Directory of C:\Documents and Settings\usr\Desktop\working\imptest
\impt
09/16/2008 04:29 PM <DIR> abc
09/16/2008 04:29 PM <DIR> defg
09/16/2008 03:40 PM 0 __init__.py
1 File(s) 0 bytes
Directory of C:\Documents and Settings\usr\Desktop\working\imptest
\impt\abc
09/16/2008 03:40 PM 13 abcmod.py
09/16/2008 03:40 PM 0 __init__.py
Directory of C:\Documents and Settings\usr\Desktop\working\imptest
\impt\defg
09/16/2008 03:40 PM 13 defmod.py
09/16/2008 03:40 PM 0 __init__.py
and this code:
>>> import impt
>>> import impt.abc
>>> import impt.abc.abcmod
>>> import impt.defg
>>> import impt.defg.defmod
I understand the import behavior will change in 3.0.
More information about the Python-list
mailing list