problem in appending a path to sys.path

Discussion in 'Python' started by ketulp_baroda@yahoo.com, Feb 25, 2004.

  1. Guest

    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??
    , Feb 25, 2004
    #1
    1. Advertising

  2. rabbits77 Guest

    >>>>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.
    rabbits77, Feb 25, 2004
    #2
    1. Advertising

  3. Peter Hansen Guest

    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
    Peter Hansen, Feb 25, 2004
    #3
  4. Guest

    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
    , Feb 26, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ronald Meier
    Replies:
    2
    Views:
    1,456
    Keith S.
    Oct 21, 2003
  2. Greg McIntyre
    Replies:
    0
    Views:
    405
    Greg McIntyre
    Sep 12, 2005
  3. gen_tricomi
    Replies:
    2
    Views:
    714
    gen_tricomi
    May 23, 2006
  4. mhearne808[insert-at-sign-here]gmail[insert-dot-he

    Appending to sys.path

    mhearne808[insert-at-sign-here]gmail[insert-dot-he, Mar 24, 2009, in forum: Python
    Replies:
    1
    Views:
    341
    Peter Otten
    Mar 24, 2009
  5. Darren Hart
    Replies:
    0
    Views:
    190
    Darren Hart
    Oct 30, 2011
Loading...

Share This Page