How do I add permanently to Pythons sys.path?

C

cnb

sys.path
['C:\\Python25\\Progs\\NatLangProc', 'C:\\Python25\\Lib\\idlelib', 'C:\
\Windows\\system32\\python25.zip', 'C:\\Python25\\lib\\site-packages\
\orange', 'C:\\Python25\\lib\\site-packages\\orange\\OrangeWidgets',
'C:\\Python25\\lib\\site-packages\\orange\\OrangeCanvas', 'C:\
\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-
packages', 'C:\\Python25\\lib\\site-packages\\Numeric', 'C:\\Python25\
\lib\\site-packages\\PIL']
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.
 
P

Python

['C:\\Python25\\Progs\\NatLangProc', 'C:\\Python25\\Lib\\idlelib',
'C:\
\Windows\\system32\\python25.zip', 'C:\\Python25\\lib\\site-packages\
\orange', 'C:\\Python25\\lib\\site-packages\\orange\\OrangeWidgets',
'C:\\Python25\\lib\\site-packages\\orange\\OrangeCanvas', 'C:\
\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-
packages', 'C:\\Python25\\lib\\site-packages\\Numeric', 'C:\\Python25\
\lib\\site-packages\\PIL']
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.
a temp solution is to append it to that list:

sys.path.append('C:/Python25/Progs/')

a permanent solution is to add it to the environment variable
(no idea where to set this in windows)
$PYTHONPATH = "/C:/Python25/Progs/"

gr
Arno
 
C

cnb

['C:\\Python25\\Progs\\NatLangProc', 'C:\\Python25\\Lib\\idlelib',  
'C:\
\Windows\\system32\\python25.zip', 'C:\\Python25\\lib\\site-packages\
\orange', 'C:\\Python25\\lib\\site-packages\\orange\\OrangeWidgets',
'C:\\Python25\\lib\\site-packages\\orange\\OrangeCanvas', 'C:\
\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-
packages', 'C:\\Python25\\lib\\site-packages\\Numeric', 'C:\\Python25\
\lib\\site-packages\\PIL']
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.

a temp solution is to append it to that list:

sys.path.append('C:/Python25/Progs/')

a permanent solution is to add it to the environment variable
(no idea where to set this in windows)
$PYTHONPATH = "/C:/Python25/Progs/"

gr
Arno

but since Python25/ is in my path it only seems to import from that
exact dir, not dirs inside the dir.

so i have to do somerthing like /progs/* ?


and also, temporary adding doesnt seem to work.
 
A

Aaron \Castironpi\ Brady

['C:\\Python25\\Progs\\NatLangProc', 'C:\\Python25\\Lib\\idlelib', 'C:\
\Windows\\system32\\python25.zip', 'C:\\Python25\\lib\\site-packages\
\orange', 'C:\\Python25\\lib\\site-packages\\orange\\OrangeWidgets',
'C:\\Python25\\lib\\site-packages\\orange\\OrangeCanvas', 'C:\
\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-
packages', 'C:\\Python25\\lib\\site-packages\\Numeric', 'C:\\Python25\
\lib\\site-packages\\PIL']



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/)
 
S

Support Desk

What about on a unix box?

Sincerely,
Michael H.


-----Original Message-----
From: Aaron "Castironpi" Brady [mailto:[email protected]]
Sent: Tuesday, September 16, 2008 12:49 PM
To: (e-mail address removed)
Subject: Re: How do I add permanently to Pythons sys.path?

['C:\\Python25\\Progs\\NatLangProc', 'C:\\Python25\\Lib\\idlelib', 'C:\
\Windows\\system32\\python25.zip', 'C:\\Python25\\lib\\site-packages\
\orange', 'C:\\Python25\\lib\\site-packages\\orange\\OrangeWidgets',
'C:\\Python25\\lib\\site-packages\\orange\\OrangeCanvas', 'C:\
\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-
packages', 'C:\\Python25\\lib\\site-packages\\Numeric', 'C:\\Python25\
\lib\\site-packages\\PIL']



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/)
 
C

cnb

['C:\\Python25\\Progs\\NatLangProc', 'C:\\Python25\\Lib\\idlelib', 'C:\
\Windows\\system32\\python25.zip', 'C:\\Python25\\lib\\site-packages\
\orange', 'C:\\Python25\\lib\\site-packages\\orange\\OrangeWidgets',
'C:\\Python25\\lib\\site-packages\\orange\\OrangeCanvas', 'C:\
\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-
packages', 'C:\\Python25\\lib\\site-packages\\Numeric', 'C:\\Python25\
\lib\\site-packages\\PIL']
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/* ?
 
A

Aaron \Castironpi\ Brady

What about on a unix box?

Do you have write permissions on, in this case, '/opt/pkgs/python-2.0/
lib/python2.0/site-packages' ? (Or the entry in your sys.path.)
['', '/opt/pkgs/python-2.0/lib/python2.0', '/opt/pkgs/python-2.0/lib/
python2.0/plat-sunos5', '/opt/pkgs/python-2.0/lib/python2.0/lib-tk', '/
opt/pkgs/python-2.0/lib/python2.0/lib-dynload', '/opt/pkgs/python-2.0/
lib/python2.0/site-packages']


Sincerely,
Michael H.

-----Original Message-----
From: Aaron "Castironpi" Brady [mailto:[email protected]]
Sent: Tuesday, September 16, 2008 12:49 PM
To: (e-mail address removed)
Subject: Re: How do I add permanently to Pythons sys.path?

['C:\\Python25\\Progs\\NatLangProc', 'C:\\Python25\\Lib\\idlelib', 'C:\
\Windows\\system32\\python25.zip', 'C:\\Python25\\lib\\site-packages\
\orange', 'C:\\Python25\\lib\\site-packages\\orange\\OrangeWidgets',
'C:\\Python25\\lib\\site-packages\\orange\\OrangeCanvas', 'C:\
\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-
packages', 'C:\\Python25\\lib\\site-packages\\Numeric', 'C:\\Python25\
\lib\\site-packages\\PIL']
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/)
 
A

Aaron \Castironpi\ Brady

On Sep 16, 7:49 pm, "Aaron \"Castironpi\" Brady"



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
 
A

Aaron \Castironpi\ Brady

What about on a unix box?

I can't help you. I don't have access to '/opt/pkgs/python-2.0/lib/
python2.0/site-packages' (ha ha) on the one I have access to. If you
do, try the same thing.

Sincerely,
Michael H.

-----Original Message-----
From: Aaron "Castironpi" Brady [mailto:[email protected]]
Sent: Tuesday, September 16, 2008 12:49 PM
To: (e-mail address removed)
Subject: Re: How do I add permanently to Pythons sys.path?

['C:\\Python25\\Progs\\NatLangProc', 'C:\\Python25\\Lib\\idlelib', 'C:\
\Windows\\system32\\python25.zip', 'C:\\Python25\\lib\\site-packages\
\orange', 'C:\\Python25\\lib\\site-packages\\orange\\OrangeWidgets',
'C:\\Python25\\lib\\site-packages\\orange\\OrangeCanvas', 'C:\
\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-
packages', 'C:\\Python25\\lib\\site-packages\\Numeric', 'C:\\Python25\
\lib\\site-packages\\PIL']
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/)
 
C

cnb

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...
 
A

Aaron \Castironpi\ Brady

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:

I understand the import behavior will change in 3.0.
 

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,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top