how to clean sys.path

siggi smusnmrNOSPAM at
Thu Jan 11 15:32:25 CET 2007

"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 at
> 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\\Python25\\Lib\\idlelib',
'C:\\Documents and Settings\\User\\My Documents\\Python25\\',
'C:\\Documents and Settings\\User\\My Documents\\Python25\\DLLs',
'C:\\Documents and Settings\\User\\My Documents\\Python25\\lib',
'C:\\Documents and Settings\\User\\My Documents\\Python25\\lib\\plat-win',
'C:\\Documents and Settings\\User\\My Documents\\Python25\\lib\\lib-tk',
'C:\\Documents and Settings\\User\\My Documents\\Python25', 'C:\\Documents
and Settings\\User\\My Documents\\Python25\\lib\\site-packages',
'C:\\Documents and Settings\\User\\My
Documents\\Python25\\lib\\site-packages\\PIL', 'C:\\Documents and
Settings\\User\\My Documents\\Python25\\lib\\site-packages\\win32',
'C:\\Documents and Settings\\User\\My
Documents\\Python25\\lib\\site-packages\\win32\\lib', 'C:\\Documents and
Settings\\User\\My Documents\\Python25\\lib\\site-packages\\Pythonwin',
'C:\\Documents and Settings\\User\\My

or in plain DOS:

C:\Documents and Settings\User\My Documents\My Python files
C:\Documents and Settings\User\My Documents\Python25\Lib\idlelib
C:\Documents and Settings\User\My Documents\Python25\
C:\Documents and Settings\User\My Documents\Python25\DLLs
C:\Documents and Settings\User\My Documents\Python25\lib
C:\Documents and Settings\User\My Documents\Python25\lib\plat-win
C:\Documents and Settings\User\My Documents\Python25\lib\lib-tk
C:\Documents and Settings\User\My Documents\Python25
C:\Documents and Settings\User\My Documents\Python25\lib\site-packages
C:\Documents and Settings\User\My Documents\Python25\lib\site-packages\PIL
C:\Documents and Settings\User\My Documents\Python25\lib\site-packages\win32
C:\Documents and Settings\User\My
C:\Documents and Settings\User\My
C:\Documents and Settings\User\My
Documents\Python25\lib\site-packages\wx-2.8-msw-ansi 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
"" 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 to ...\My Python Files\  , nothing happens after
running it with IDLE or in the command line.
Appending 'C:\Documents and Settings\User\My 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\My Documents\My Python files', 'C:\Documents
and Settings\User\My Documents\My Python files\wxDemos'. Now \wxDemos\ is
being searched very early.

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

Traceback (most recent call last):
  File "C:\Documents and Settings\My Documents\My Python
files\", 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\My Documents\My Python files\wxDemos'. And
does work when residing in that directory.

Can you help me again?



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

More information about the Python-list mailing list