how do i add a new path into sys.path?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • wen

    #1

    how do i add a new path into sys.path?

    on my system(win2k server, python 2.3.5),[color=blue][color=green][color=darkred]
    >>> import sys
    >>> print sys.path[/color][/color][/color]
    ['C:\\', 'C:\\WINNT\\sys tem32\\python23 .zip',
    'C:\\Python23\\ lib\\site-packages\\Pytho nwin',
    'C:\\Python23\\ lib\\site-packages\\win32 ',
    'C:\\Python23\\ lib\\site-packages\\win32 \\lib',
    'C:\\Python23\\ lib\\site-packages', 'C:\\Python23\\ DLLs',
    'C:\\Python23\\ lib', 'C:\\Python23\\ lib\\plat-win',
    'C:\\Python23\\ lib\\lib-tk', 'C:\\Python23', 'D:\\Program Files\\DeLano
    Scientific\\PyM OL\\modules']

    now, i wanna add "C:\Python23\Pm w\Pmw_1_2\lib" into sys.path, how?

    any help would be appreciated.

    with my kind regards,
    Wen


  • apa

    #2
    Re: how do i add a new path into sys.path?

    You can do it this way:

    sys.path.append ("C:\Temp")

    Alejandro

    Comment

    • bruno modulix

      #3
      Re: how do i add a new path into sys.path?

      wen wrote:[color=blue]
      > on my system(win2k server, python 2.3.5),
      >[color=green][color=darkred]
      >>>>import sys
      >>>>print sys.path[/color][/color]
      >
      > ['C:\\', 'C:\\WINNT\\sys tem32\\python23 .zip',
      > 'C:\\Python23\\ lib\\site-packages\\Pytho nwin',
      > 'C:\\Python23\\ lib\\site-packages\\win32 ',
      > 'C:\\Python23\\ lib\\site-packages\\win32 \\lib',
      > 'C:\\Python23\\ lib\\site-packages', 'C:\\Python23\\ DLLs',
      > 'C:\\Python23\\ lib', 'C:\\Python23\\ lib\\plat-win',
      > 'C:\\Python23\\ lib\\lib-tk', 'C:\\Python23', 'D:\\Program Files\\DeLano
      > Scientific\\PyM OL\\modules']
      >
      > now, i wanna add "C:\Python23\Pm w\Pmw_1_2\lib" into sys.path, how?[/color]
      [color=blue]
      > any help would be appreciated.[/color]

      hint 1: Python lists have an append() and an insert() method
      hint 2: sys.path is a list

      HTH
      --
      bruno desthuilliers
      python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
      p in 'onurb@xiludom. gro'.split('@')])"

      Comment

      • wen

        #4
        Re: how do i add a new path into sys.path?

        if i wanna add the path "C:\temp" into sys.path, and make it available for
        any other new python apps, like i add C:\temp into windows path , how?
        thank you.

        "apa" <apadovan@gmail .com> wrote in message
        news:1124353535 .829964.208660@ o13g2000cwo.goo glegroups.com.. .[color=blue]
        > You can do it this way:
        >
        > sys.path.append ("C:\Temp")
        >
        > Alejandro
        >[/color]


        Comment

        • poyol@hotmail.com

          #5
          Re: how do i add a new path into sys.path?


          wen wrote:[color=blue]
          > if i wanna add the path "C:\temp" into sys.path, and make it available for
          > any other new python apps, like i add C:\temp into windows path , how?
          > thank you.[/color]

          Then use PYTHONPATH as you would use PATH .....

          Comment

          • wen

            #6
            Re: how do i add a new path into sys.path?

            if i wanna add the path "C:\temp" into sys.path, and make it available for
            any other new python apps, like i add C:\temp into windows path , how?
            thank you.

            "apa" <apadovan@gmail .com> wrote in message
            news:1124353535 .829964.208660@ o13g2000cwo.goo glegroups.com.. .[color=blue]
            > You can do it this way:
            >
            > sys.path.append ("C:\Temp")
            >
            > Alejandro
            >[/color]


            Comment

            • Steve Holden

              #7
              Re: how do i add a new path into sys.path?

              apa wrote:[color=blue]
              > You can do it this way:
              >
              > sys.path.append ("C:\Temp")
              >
              > Alejandro
              >[/color]
              Better:

              sys.path.append ("C:\\Temp")

              or

              sys.path.append (r"C:\Temp")

              regards
              Steve
              --
              Steve Holden +44 150 684 7255 +1 800 494 3119
              Holden Web LLC http://www.holdenweb.com/

              Comment

              • John Machin

                #8
                Re: how do i add a new path into sys.path?

                wen wrote:[color=blue]
                > on my system(win2k server, python 2.3.5),
                >[color=green][color=darkred]
                >>>>import sys
                >>>>print sys.path[/color][/color]
                >
                > ['C:\\', 'C:\\WINNT\\sys tem32\\python23 .zip',
                > 'C:\\Python23\\ lib\\site-packages\\Pytho nwin',
                > 'C:\\Python23\\ lib\\site-packages\\win32 ',
                > 'C:\\Python23\\ lib\\site-packages\\win32 \\lib',
                > 'C:\\Python23\\ lib\\site-packages', 'C:\\Python23\\ DLLs',
                > 'C:\\Python23\\ lib', 'C:\\Python23\\ lib\\plat-win',
                > 'C:\\Python23\\ lib\\lib-tk', 'C:\\Python23', 'D:\\Program Files\\DeLano
                > Scientific\\PyM OL\\modules']
                >
                > now, i wanna add "C:\Python23\Pm w\Pmw_1_2\lib" into sys.path, how?
                >
                > any help would be appreciated.
                >
                > with my kind regards,
                > Wen
                >
                >[/color]

                cat clpyaibot.log
                * sys.path is instance of <list>.
                * "C:\Python23\Pm w\Pmw_1_2\lib" is a [non-raw, living dangerously] string.
                * does not compute, trying again under various failure modes ...
                * detected Shift key failure
                * interpreting "wanna" as "want to"
                * parsed chunk: """I want to add <str> into <list>"""
                * no such keyword: "add"
                * <str>.add ... not found
                * <list>.into ... not found
                * <list>.addint o ... not found
                * checking plausible alternatives ...
                * <list>.append(< object>)
                * <list>.insert(< index>, <object>)

                Comment

                • James Sungjin Kim

                  #9
                  Re: how do i add a new path into sys.path?

                  Steve Holden wrote:[color=blue]
                  > sys.path.append (r"C:\Temp")[/color]

                  In this case, do I need to save the refined path, i.e, the original
                  paths + the new path (r"C:\Temp"), by using some command in order to use
                  it permanently. if yes, it would be greatly appreciated to noitce the
                  correspoding command and the usage of it.

                  -James

                  Comment

                  • Steve Holden

                    #10
                    Re: how do i add a new path into sys.path?

                    James Sungjin Kim wrote:[color=blue]
                    > Steve Holden wrote:
                    >[color=green]
                    >>sys.path.appe nd(r"C:\Temp")[/color]
                    >
                    >
                    > In this case, do I need to save the refined path, i.e, the original
                    > paths + the new path (r"C:\Temp"), by using some command in order to use
                    > it permanently. if yes, it would be greatly appreciated to noitce the
                    > correspoding command and the usage of it.
                    >
                    > -James[/color]

                    The method I outlined works only for the duration of a single program
                    run, because the sys.path variable is set up each time you run the
                    Python interpreter. You need to look at the suggestions you've had for
                    setting the PYTHONPATH environment variable to effect changes to all
                    future Python execution.

                    Essentially this is most usually done in the "My Computer -> Properties"
                    dialog: click the "environmen t variables" button and create a new
                    (all-users or private, depending on your needs) environment variable
                    called PYTHONPATH containing a semicolon-separated list of directories
                    the interpreter should add to the path.

                    regards
                    Steve
                    --
                    Steve Holden +44 150 684 7255 +1 800 494 3119
                    Holden Web LLC http://www.holdenweb.com/

                    Comment

                    • Peter Hansen

                      #11
                      Re: how do i add a new path into sys.path?

                      Steve Holden wrote:[color=blue]
                      > The method I outlined works only for the duration of a single program
                      > run, because the sys.path variable is set up each time you run the
                      > Python interpreter. You need to look at the suggestions you've had for
                      > setting the PYTHONPATH environment variable to effect changes to all
                      > future Python execution.[/color]

                      Or, often better and cleaner, use .pth files as described in the
                      documentation for the standard library "site" module.

                      -Peter

                      Comment

                      Working...