problem in appending a path to sys.path

K

ketulp_baroda

Hi
I am having a problem in appending to sys.path
I am doing it this way:['D:\\PYTHON23', 'D:\\PYTHON23\\Lib\\idlelib',
'D:\\WINNT\\system32\\python23.zip',
'D:\\PYTHON23\\lib\\site-packages\\Pythonwin',
'D:\\PYTHON23\\lib\\site-packages\\win32',
'D:\\PYTHON23\\lib\\site-packages\\win32\\lib',
'D:\\PYTHON23\\lib\\site-packages', 'D:\\Python23\\DLLs',
'D:\\Python23\\lib', 'D:\\Python23\\lib\\plat-win',
'D:\\Python23\\lib\\lib-tk', 'D:\\Python23']['D:\\PYTHON23', 'D:\\PYTHON23\\Lib\\idlelib',
'D:\\WINNT\\system32\\python23.zip',
'D:\\PYTHON23\\lib\\site-packages\\Pythonwin',
'D:\\PYTHON23\\lib\\site-packages\\win32',
'D:\\PYTHON23\\lib\\site-packages\\win32\\lib',
'D:\\PYTHON23\\lib\\site-packages', 'D:\\Python23\\DLLs',
'D:\\Python23\\lib', 'D:\\Python23\\lib\\plat-win',
'D:\\Python23\\lib\\lib-tk', 'D:\\Python23',
'D:\\Python23\\Lib\\site-packages\\code']

But when I close the shell and now again open it & do sys.path , it
doesnt show the path I last appended. i.e
['D:\\PYTHON23', 'D:\\PYTHON23\\Lib\\idlelib',
'D:\\WINNT\\system32\\python23.zip',
'D:\\PYTHON23\\lib\\site-packages\\Pythonwin',
'D:\\PYTHON23\\lib\\site-packages\\win32',
'D:\\PYTHON23\\lib\\site-packages\\win32\\lib',
'D:\\PYTHON23\\lib\\site-packages', 'D:\\Python23\\DLLs',
'D:\\Python23\\lib', 'D:\\Python23\\lib\\plat-win',
'D:\\Python23\\lib\\lib-tk', 'D:\\Python23']

What am I doing wrong here??
 
R

rabbits77

sys.path.append(r'D:\Python23\Lib\site-packages\code')
['D:\\PYTHON23', 'D:\\PYTHON23\\Lib\\idlelib',
'D:\\WINNT\\system32\\python23.zip',
'D:\\PYTHON23\\lib\\site-packages\\Pythonwin',
'D:\\PYTHON23\\lib\\site-packages\\win32',
'D:\\PYTHON23\\lib\\site-packages\\win32\\lib',
'D:\\PYTHON23\\lib\\site-packages', 'D:\\Python23\\DLLs',
'D:\\Python23\\lib', 'D:\\Python23\\lib\\plat-win',
'D:\\Python23\\lib\\lib-tk', 'D:\\Python23',
'D:\\Python23\\Lib\\site-packages\\code']

But when I close the shell and now again open it & do sys.path , it
doesnt show the path I last appended. i.e


['D:\\PYTHON23', 'D:\\PYTHON23\\Lib\\idlelib',
'D:\\WINNT\\system32\\python23.zip',
'D:\\PYTHON23\\lib\\site-packages\\Pythonwin',
'D:\\PYTHON23\\lib\\site-packages\\win32',
'D:\\PYTHON23\\lib\\site-packages\\win32\\lib',
'D:\\PYTHON23\\lib\\site-packages', 'D:\\Python23\\DLLs',
'D:\\Python23\\lib', 'D:\\Python23\\lib\\plat-win',
'D:\\Python23\\lib\\lib-tk', 'D:\\Python23']

What am I doing wrong here??
sys.path changed for the same reason why if you set
a="puke"
in the interpreter and then closed the shell and restarted the
interpreter, the variable a would have no value!!
You are not making a permanent change to sys.path using sys.append!!
I think you really want to modify the PYTHONPATH environment variable,
I'd guess.
 
P

Peter Hansen

What am I doing wrong here??

As rabbits77 said, your change is not being persisted. What you
can do instead of using PYTHONPATH, if you wish, is read the header
comment in the file python\lib\site.py (i.e. look in your Python
folder tree for that file) and create a ".pth" file with the appropriate
contents. As you are on Windows, make sure you take care to create it
with a lower-case extension, not .PTH, as site.py is case-sensitive in
this respect.

-Peter
 
K

ketulp_baroda

Peter Hansen said:
As rabbits77 said, your change is not being persisted. What you
can do instead of using PYTHONPATH, if you wish, is read the header
comment in the file python\lib\site.py (i.e. look in your Python
folder tree for that file) and create a ".pth" file with the appropriate
contents. As you are on Windows, make sure you take care to create it
with a lower-case extension, not .PTH, as site.py is case-sensitive in
this respect.

-Peter
Thanks
this is exactly what I was looking for
 

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,765
Messages
2,569,568
Members
45,042
Latest member
icassiem

Latest Threads

Top