Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > problem in appending a path to sys.path

Reply
Thread Tools

problem in appending a path to sys.path

 
 
ketulp_baroda@yahoo.com
Guest
Posts: n/a
 
      02-25-2004
Hi
I am having a problem in appending to sys.path
I am doing it this way:
>>> sys.path

['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']
>>> sys.path.append(r'D:\Python23\Lib\site-packages\code')
>>> sys.path

['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

>>> import sys
>>> sys.path

['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??
 
Reply With Quote
 
 
 
 
rabbits77
Guest
Posts: n/a
 
      02-25-2004
>>>>sys.path.append(r'D:\Python23\Lib\site-packages\code')
>>>>sys.path

>
> ['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
>
>
>>>>import sys
>>>>sys.path

>
> ['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.

 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      02-25-2004
wrote:
>
> 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
 
Reply With Quote
 
ketulp_baroda@yahoo.com
Guest
Posts: n/a
 
      02-26-2004
Peter Hansen <> wrote in message news:<>...
> wrote:
> >
> > 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

Thanks
this is exactly what I was looking for
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Appending to sys.path during module install with distutils Darren Hart Python 0 10-30-2011 09:04 PM
Appending to sys.path mhearne808[insert-at-sign-here]gmail[insert-dot-here]com Python 1 03-24-2009 04:01 PM
Problem appending Objects to File Marcelo Java 5 10-25-2005 12:55 PM
Appending paths relative to the current file to sys.path Greg McIntyre Python 0 09-12-2005 06:21 AM
Appending to the path statement TinCanMan Computer Support 1 06-02-2004 06:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57