how to clean sys.path

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

    #1

    how to clean sys.path

    Hi all,

    when I do >>>sys.path in IDLE (winXP), i get a horrendously long list of
    paths, paths I may have used during a lot of trials and errors. How can I
    clean up sys.path? I mean, trim it of unnecessary paths?

    So far, I know only the command >>>sys.path.app end(r'c:....etc ...'), but how
    to delete or insert at the beginning of the list, I know not.

    Thanks,

    siggi


  • Laszlo Nagy

    #2
    Re: how to clean sys.path

    >
    So far, I know only the command >>>sys.path.app end(r'c:....etc ...'), but how
    to delete or insert at the beginning of the list, I know not.
    >
    You can delete a slice. For example,

    del sys.path[2:5]

    More about slicing: http://docs.python.org/ref/slicings.html
    sys.path is a regular list. List methods:


    Best,

    Laszlo

    Comment

    • siggi

      #3
      Re: how to clean sys.path

      Thank you Laszlo!

      Take care,

      siggi

      "Laszlo Nagy" <gandalf@design aproduct.bizsch rieb im Newsbeitrag
      news:mailman.24 89.1168367359.3 2031.python-list@python.org ...
      >
      >>
      >So far, I know only the command >>>sys.path.app end(r'c:....etc ...'), but
      >how to delete or insert at the beginning of the list, I know not.
      >>
      You can delete a slice. For example,
      >
      del sys.path[2:5]
      >
      More about slicing: http://docs.python.org/ref/slicings.html
      sys.path is a regular list. List methods:

      >
      Best,
      >
      Laszlo
      >

      Comment

      • Tim Roberts

        #4
        Re: how to clean sys.path

        "siggi" <smusnmrNOSPAM@ yahoo.comwrote:
        >
        >when I do >>>sys.path in IDLE (winXP), i get a horrendously long list of
        >paths, paths I may have used during a lot of trials and errors. How can I
        >clean up sys.path? I mean, trim it of unnecessary paths?
        What do mean by "used during a lot of trials and errors"? sys.path is
        recreated from scratch every time Python starts. It doesn't accumulate
        over time, other than from new packages that you install.
        --
        Tim Roberts, timr@probo.com
        Providenza & Boekelheide, Inc.

        Comment

        • siggi

          #5
          Re: how to clean sys.path

          "Tim Roberts" wrote:
          >>
          >>when I do >>>sys.path in IDLE (winXP), i get a horrendously long list of
          >>paths, paths I may have used during a lot of trials and errors. How can I
          >>clean up sys.path? I mean, trim it of unnecessary paths?
          >
          What do mean by "used during a lot of trials and errors"? sys.path is
          recreated from scratch every time Python starts. It doesn't accumulate
          over time, other than from new packages that you install.
          --
          Tim Roberts, timr@probo.com
          Providenza & Boekelheide, Inc.

          Sorry Tim, my statement was not correct, due to my inexperience with Python.
          And sorry, too, for my somewhat lengthy reply:
          After having had inspected my current sys.path...

          ['C:\\Documents and Settings\\User\ \My Documents\\My Python files',
          'C:\\Documents and Settings\\User\ \My Documents\\Pyth on25\\Lib\\idle lib',
          'C:\\Documents and Settings\\User\ \My Documents\\Pyth on25\\python25. zip',
          'C:\\Documents and Settings\\User\ \My Documents\\Pyth on25\\DLLs',
          'C:\\Documents and Settings\\User\ \My Documents\\Pyth on25\\lib',
          'C:\\Documents and Settings\\User\ \My Documents\\Pyth on25\\lib\\plat-win',
          'C:\\Documents and Settings\\User\ \My Documents\\Pyth on25\\lib\\lib-tk',
          'C:\\Documents and Settings\\User\ \My Documents\\Pyth on25', 'C:\\Documents
          and Settings\\User\ \My Documents\\Pyth on25\\lib\\site-packages',
          'C:\\Documents and Settings\\User\ \My
          Documents\\Pyth on25\\lib\\site-packages\\PIL', 'C:\\Documents and
          Settings\\User\ \My Documents\\Pyth on25\\lib\\site-packages\\win32 ',
          'C:\\Documents and Settings\\User\ \My
          Documents\\Pyth on25\\lib\\site-packages\\win32 \\lib', 'C:\\Documents and
          Settings\\User\ \My Documents\\Pyth on25\\lib\\site-packages\\Pytho nwin',
          'C:\\Documents and Settings\\User\ \My
          Documents\\Pyth on25\\lib\\site-packages\\wx-2.8-msw-ansi']

          or in plain DOS:

          C:\Documents and Settings\User\M y Documents\My Python files
          C:\Documents and Settings\User\M y Documents\Pytho n25\Lib\idlelib
          C:\Documents and Settings\User\M y Documents\Pytho n25\python25.zi p
          C:\Documents and Settings\User\M y Documents\Pytho n25\DLLs
          C:\Documents and Settings\User\M y Documents\Pytho n25\lib
          C:\Documents and Settings\User\M y Documents\Pytho n25\lib\plat-win
          C:\Documents and Settings\User\M y Documents\Pytho n25\lib\lib-tk
          C:\Documents and Settings\User\M y Documents\Pytho n25
          C:\Documents and Settings\User\M y Documents\Pytho n25\lib\site-packages
          C:\Documents and Settings\User\M y Documents\Pytho n25\lib\site-packages\PIL
          C:\Documents and Settings\User\M y Documents\Pytho n25\lib\site-packages\win32
          C:\Documents and Settings\User\M y
          Documents\Pytho n25\lib\site-packages\win32\ lib
          C:\Documents and Settings\User\M y
          Documents\Pytho n25\lib\site-packages\Python win
          C:\Documents and Settings\User\M y
          Documents\Pytho n25\lib\site-packages\wx-2.8-msw-ansi

          ....it just looked horrible to me at first sight!

          If I interpret your explanation correctly, all these paths are necessary,
          and not relics of previous installations and deinstallations .

          What puzzles me, though, is, that e.g., when I run the wxPython application
          "AnalogClock.py " with IDLE or in the command line , this works only in the
          directory "...\My Python files\wxDemos\" . This directory contains all files
          and folders from the original "\wx-2.8-msw-ansi\demos\").

          When I copy AnalogClock.py to ...\My Python Files\ , nothing happens after
          running it with IDLE or in the command line.
          Appending 'C:\Documents and Settings\User\M y Documents\My Python
          files\wxDemos ' to the sys.path does not help either.

          Thinking that I am clever, I changed my sys.path with sclicing and
          concatenation such that my sys.path starts with

          'C:\Documents and Settings\User\M y Documents\My Python files', 'C:\Documents
          and Settings\User\M y Documents\My Python files\wxDemos'. Now \wxDemos\ is
          being searched very early.

          .... no way! After running AnalogClock.py again, this error message appears:

          ------------------------------------------
          Traceback (most recent call last):
          File "C:\Documen ts and Settings\My Documents\My Python
          files\wxAnalogC lock.py", line 14, in <module>
          import wx
          ImportError: No module named wx.
          ------------------------------------------

          Very strange! Because all this wx stuff IS IN the directory 'C:\Documents
          and Settings\User\M y Documents\My Python files\wxDemos'. And AnalogClock.py
          does work when residing in that directory.

          Can you help me again?

          Thanks,

          siggi

          P.S. On another PC where the python program is in c:\programs\pyt hon25\,
          same as above!






          Comment

          • Tim Roberts

            #6
            Re: how to clean sys.path

            "siggi" <smusnmrNOSPAM@ yahoo.comwrote:
            >
            >or in plain DOS:
            >
            >C:\Documents and Settings\User\M y Documents\My Python files
            >C:\Documents and Settings\User\M y Documents\Pytho n25\Lib\idlelib
            >C:\Documents and Settings\User\M y Documents\Pytho n25\python25.zi p
            >C:\Documents and Settings\User\M y Documents\Pytho n25\DLLs
            >C:\Documents and Settings\User\M y Documents\Pytho n25\lib
            >C:\Documents and Settings\User\M y Documents\Pytho n25\lib\plat-win
            >C:\Documents and Settings\User\M y Documents\Pytho n25\lib\lib-tk
            >C:\Documents and Settings\User\M y Documents\Pytho n25
            >C:\Documents and Settings\User\M y Documents\Pytho n25\lib\site-packages
            >C:\Documents and Settings\User\M y Documents\Pytho n25\lib\site-packages\PIL
            >C:\Documents and Settings\User\M y Documents\Pytho n25\lib\site-packages\win32
            >C:\Documents and Settings\User\M y
            >Documents\Pyth on25\lib\site-packages\win32\ lib
            >C:\Documents and Settings\User\M y
            >Documents\Pyth on25\lib\site-packages\Python win
            >C:\Documents and Settings\User\M y
            >Documents\Pyth on25\lib\site-packages\wx-2.8-msw-ansi
            >
            >...it just looked horrible to me at first sight!
            It looks horrible to me, too. That's why I install applications like that
            in "\Apps" instead of a document off of Documents and setings. This looks
            much better:

            C:\Documents and Settings\User\M y Documents\My Python files
            C:\Apps\Python2 5\Lib\idlelib
            C:\Apps\Python2 5\python25.zip
            C:\Apps\Python2 5\DLLs
            C:\Apps\Python2 5\lib
            C:\Apps\Python2 5\lib\plat-win
            C:\Apps\Python2 5\lib\lib-tk
            C:\Apps\Python2 5
            C:\Apps\Python2 5\lib\site-packages
            C:\Apps\Python2 5\lib\site-packages\PIL
            C:\Apps\Python2 5\lib\site-packages\win32
            C:\Apps\Python2 5\lib\site-packages\win32\ lib
            C:\Apps\Python2 5\lib\site-packages\Python win
            C:\Apps\Python2 5\lib\site-packages\wx-2.8-msw-ansi

            Searching these doesn't really take very long. Remember that it doesn't
            have to read all the files -- it only has to read the directories.
            >'C:\Document s and Settings\User\M y Documents\My Python files', 'C:\Documents
            >and Settings\User\M y Documents\My Python files\wxDemos'. Now \wxDemos\ is
            >being searched very early.
            >
            >... no way! After running AnalogClock.py again, this error message appears:
            >
            >------------------------------------------
            >Traceback (most recent call last):
            File "C:\Documen ts and Settings\My Documents\My Python
            >files\wxAnalog Clock.py", line 14, in <module>
            import wx
            >ImportError: No module named wx.
            >------------------------------------------
            >
            >Very strange! Because all this wx stuff IS IN the directory 'C:\Documents
            >and Settings\User\M y Documents\My Python files\wxDemos'. And AnalogClock.py
            >does work when residing in that directory.
            wxDemos contains the demos. The "wx" module lives in
            site-packages\wx-2.8-msw-ansi. Did you leave that in?
            --
            Tim Roberts, timr@probo.com
            Providenza & Boekelheide, Inc.

            Comment

            • Siggi

              #7
              Re: how to clean sys.path


              "Tim Roberts" wrote:
              >wxDemos contains the demos. The "wx" module lives in
              >site-packages\wx-2.8-msw-ansi. Did you leave that in?
              Yes! Even on this computer I am writing now with - where the whole Python
              programs stuff is in a programs folder, such as

              C:\Programs\Pyt hon25\Lib\site-packages\wx-2.8-msw-ansi

              - it is the same problem!

              "siggi" <smusnmrNOSPAM@ yahoo.comwrote:
              >>
              >>or in plain DOS:
              >>
              >>C:\Document s and Settings\User\M y Documents\My Python files
              >>C:\Document s and Settings\User\M y Documents\Pytho n25\Lib\idlelib
              >>C:\Document s and Settings\User\M y Documents\Pytho n25\python25.zi p
              >>C:\Document s and Settings\User\M y Documents\Pytho n25\DLLs
              >>C:\Document s and Settings\User\M y Documents\Pytho n25\lib
              >>C:\Document s and Settings\User\M y Documents\Pytho n25\lib\plat-win
              >>C:\Document s and Settings\User\M y Documents\Pytho n25\lib\lib-tk
              >>C:\Document s and Settings\User\M y Documents\Pytho n25
              >>C:\Document s and Settings\User\M y Documents\Pytho n25\lib\site-packages
              >>C:\Document s and Settings\User\M y Documents\Pytho n25\lib\site-packages\PIL
              >>C:\Document s and Settings\User\M y
              >>Documents\Pyt hon25\lib\site-packages\win32
              >>C:\Document s and Settings\User\M y
              >>Documents\Pyt hon25\lib\site-packages\win32\ lib
              >>C:\Document s and Settings\User\M y
              >>Documents\Pyt hon25\lib\site-packages\Python win
              >>C:\Document s and Settings\User\M y
              >>Documents\Pyt hon25\lib\site-packages\wx-2.8-msw-ansi
              >>
              >>...it just looked horrible to me at first sight!
              >
              It looks horrible to me, too. That's why I install applications like that
              in "\Apps" instead of a document off of Documents and setings. This looks
              much better:
              >
              C:\Documents and Settings\User\M y Documents\My Python files
              C:\Apps\Python2 5\Lib\idlelib
              C:\Apps\Python2 5\python25.zip
              C:\Apps\Python2 5\DLLs
              C:\Apps\Python2 5\lib
              C:\Apps\Python2 5\lib\plat-win
              C:\Apps\Python2 5\lib\lib-tk
              C:\Apps\Python2 5
              C:\Apps\Python2 5\lib\site-packages
              C:\Apps\Python2 5\lib\site-packages\PIL
              C:\Apps\Python2 5\lib\site-packages\win32
              C:\Apps\Python2 5\lib\site-packages\win32\ lib
              C:\Apps\Python2 5\lib\site-packages\Python win
              C:\Apps\Python2 5\lib\site-packages\wx-2.8-msw-ansi
              >
              Searching these doesn't really take very long. Remember that it doesn't
              have to read all the files -- it only has to read the directories.
              >
              >>'C:\Documen ts and Settings\User\M y Documents\My Python files',
              >>'C:\Documen ts
              >>and Settings\User\M y Documents\My Python files\wxDemos'. Now \wxDemos\ is
              >>being searched very early.
              >>
              >>... no way! After running AnalogClock.py again, this error message
              >>appears:
              >>
              >>------------------------------------------
              >>Traceback (most recent call last):
              > File "C:\Documen ts and Settings\My Documents\My Python
              >>files\wxAnalo gClock.py", line 14, in <module>
              > import wx
              >>ImportError : No module named wx.
              >>------------------------------------------
              >>
              >>Very strange! Because all this wx stuff IS IN the directory 'C:\Documents
              >>and Settings\User\M y Documents\My Python files\wxDemos'. And
              >>AnalogClock.p y
              >>does work when residing in that directory.
              >
              wxDemos contains the demos. The "wx" module lives in
              site-packages\wx-2.8-msw-ansi. Did you leave that in?
              --
              Tim Roberts, timr@probo.com
              Providenza & Boekelheide, Inc.



              Comment

              • siggi

                #8
                Problem with findinf wx modules solved

                I included the "...\wxDemo s" path in PYTHONPATH. Everthing fine now!

                "siggi" <smusnmrNOSPAM@ yahoo.comschrie b im Newsbeitrag
                news:eo5hpp$2tm o$1@zam602.zam. kfa-juelich.de...
                "Tim Roberts" wrote:
                >>>
                >>>when I do >>>sys.path in IDLE (winXP), i get a horrendously long list of
                >>>paths, paths I may have used during a lot of trials and errors. How can I
                >>>clean up sys.path? I mean, trim it of unnecessary paths?
                >>
                >What do mean by "used during a lot of trials and errors"? sys.path is
                >recreated from scratch every time Python starts. It doesn't accumulate
                >over time, other than from new packages that you install.
                >--
                >Tim Roberts, timr@probo.com
                >Providenza & Boekelheide, Inc.
                >
                >
                Sorry Tim, my statement was not correct, due to my inexperience with
                Python.
                And sorry, too, for my somewhat lengthy reply:
                After having had inspected my current sys.path...
                >
                ['C:\\Documents and Settings\\User\ \My Documents\\My Python files',
                'C:\\Documents and Settings\\User\ \My Documents\\Pyth on25\\Lib\\idle lib',
                'C:\\Documents and Settings\\User\ \My Documents\\Pyth on25\\python25. zip',
                'C:\\Documents and Settings\\User\ \My Documents\\Pyth on25\\DLLs',
                'C:\\Documents and Settings\\User\ \My Documents\\Pyth on25\\lib',
                'C:\\Documents and Settings\\User\ \My Documents\\Pyth on25\\lib\\plat-win',
                'C:\\Documents and Settings\\User\ \My Documents\\Pyth on25\\lib\\lib-tk',
                'C:\\Documents and Settings\\User\ \My Documents\\Pyth on25', 'C:\\Documents
                and Settings\\User\ \My Documents\\Pyth on25\\lib\\site-packages',
                'C:\\Documents and Settings\\User\ \My
                Documents\\Pyth on25\\lib\\site-packages\\PIL', 'C:\\Documents and
                Settings\\User\ \My Documents\\Pyth on25\\lib\\site-packages\\win32 ',
                'C:\\Documents and Settings\\User\ \My
                Documents\\Pyth on25\\lib\\site-packages\\win32 \\lib', 'C:\\Documents and
                Settings\\User\ \My Documents\\Pyth on25\\lib\\site-packages\\Pytho nwin',
                'C:\\Documents and Settings\\User\ \My
                Documents\\Pyth on25\\lib\\site-packages\\wx-2.8-msw-ansi']
                >
                or in plain DOS:
                >
                C:\Documents and Settings\User\M y Documents\My Python files
                C:\Documents and Settings\User\M y Documents\Pytho n25\Lib\idlelib
                C:\Documents and Settings\User\M y Documents\Pytho n25\python25.zi p
                C:\Documents and Settings\User\M y Documents\Pytho n25\DLLs
                C:\Documents and Settings\User\M y Documents\Pytho n25\lib
                C:\Documents and Settings\User\M y Documents\Pytho n25\lib\plat-win
                C:\Documents and Settings\User\M y Documents\Pytho n25\lib\lib-tk
                C:\Documents and Settings\User\M y Documents\Pytho n25
                C:\Documents and Settings\User\M y Documents\Pytho n25\lib\site-packages
                C:\Documents and Settings\User\M y Documents\Pytho n25\lib\site-packages\PIL
                C:\Documents and Settings\User\M y
                Documents\Pytho n25\lib\site-packages\win32
                C:\Documents and Settings\User\M y
                Documents\Pytho n25\lib\site-packages\win32\ lib
                C:\Documents and Settings\User\M y
                Documents\Pytho n25\lib\site-packages\Python win
                C:\Documents and Settings\User\M y
                Documents\Pytho n25\lib\site-packages\wx-2.8-msw-ansi
                >
                ...it just looked horrible to me at first sight!
                >
                If I interpret your explanation correctly, all these paths are necessary,
                and not relics of previous installations and deinstallations .
                >
                What puzzles me, though, is, that e.g., when I run the wxPython
                application
                "AnalogClock.py " with IDLE or in the command line , this works only in the
                directory "...\My Python files\wxDemos\" . This directory contains all
                files
                and folders from the original "\wx-2.8-msw-ansi\demos\").
                >
                When I copy AnalogClock.py to ...\My Python Files\ , nothing happens
                after
                running it with IDLE or in the command line.
                Appending 'C:\Documents and Settings\User\M y Documents\My Python
                files\wxDemos ' to the sys.path does not help either.
                >
                Thinking that I am clever, I changed my sys.path with sclicing and
                concatenation such that my sys.path starts with
                >
                'C:\Documents and Settings\User\M y Documents\My Python files',
                'C:\Documents
                and Settings\User\M y Documents\My Python files\wxDemos'. Now \wxDemos\ is
                being searched very early.
                >
                ... no way! After running AnalogClock.py again, this error message
                appears:
                >
                ------------------------------------------
                Traceback (most recent call last):
                File "C:\Documen ts and Settings\My Documents\My Python
                files\wxAnalogC lock.py", line 14, in <module>
                import wx
                ImportError: No module named wx.
                ------------------------------------------
                >
                Very strange! Because all this wx stuff IS IN the directory 'C:\Documents
                and Settings\User\M y Documents\My Python files\wxDemos'. And
                AnalogClock.py
                does work when residing in that directory.
                >
                Can you help me again?
                >
                Thanks,
                >
                siggi
                >
                P.S. On another PC where the python program is in c:\programs\pyt hon25\,
                same as above!
                >
                >
                >
                >
                >
                >

                Comment

                Working...