473,732 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jan 9 '07 #1
7 12867
>
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:
http://docs.python.org/tut/node7.html

Best,

Laszlo

Jan 9 '07 #2
Thank you Laszlo!

Take care,

siggi

"Laszlo Nagy" <ga*****@design aproduct.bizsch rieb im Newsbeitrag
news:ma******** *************** *************** *@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:
http://docs.python.org/tut/node7.html

Best,

Laszlo

Jan 10 '07 #3
"siggi" <sm***********@ 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, ti**@probo.com
Providenza & Boekelheide, Inc.
Jan 11 '07 #4
"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, ti**@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!


Jan 11 '07 #5
"siggi" <sm***********@ 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, ti**@probo.com
Providenza & Boekelheide, Inc.
Jan 13 '07 #6

"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" <sm***********@ 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, ti**@probo.com
Providenza & Boekelheide, Inc.

Jan 13 '07 #7
I included the "...\wxDemo s" path in PYTHONPATH. Everthing fine now!

"siggi" <sm***********@ yahoo.comschrie b im Newsbeitrag
news:eo******** ***@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, ti**@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!


Jan 15 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2079
by: somaboy mx | last post by:
I'm looking for a way to come up with clean urls like http://www.mysite.com/products/233 instead of http://www.mysite.com/products.php?pid=233 without having to rely on mod_rewrite or other server-specific solutions. any suggestions, links to articles etc? thanks. ..soma
7
2701
by: cpnet | last post by:
I've figured out how to use the <customErrors/> element in my web config file to to redirect 404 errors to a custom error handler. But, it displays an 'ugly' URL in the client's browser. For example, if someone browses to: www.mydomain.com/Users/BobJones/ then my app should display a page with info about Bob Jones. www.mydomain.com/Users/ is a real folder on my website that only contains a single file (default.aspx). I've configured...
0
2152
by: Stefan Krah | last post by:
Hello, I'm trying to run a Python script as a Windows service with a defined shutdown. The script (enigma-client.py) handles the communications with the server in a distributed computing effort and calls a C program (enigma.exe) to do the computations. enigma.exe should save its current state when receiving SIGINT or SIGTERM. This (obviously) works under Unix and also when running the script from the Windows command line and...
2
4563
by: Ronald | last post by:
I just started with dotnetnuke, and with a wrong login (wrong password on a clean install i can crash the application pool from IIS. (when i login with the right username/password information the site works fine, i can do anything it is supposed to do) I have the following setup: -Windows 2003 x64 (fully patched, clean install) -Dotnetframework 2.0.50727 -Dotnetnuke 4.3.1
232
13302
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
7
3789
by: Ben | last post by:
Hi We are looking for a component that offers that offers the below for Tiff files: Image clean-up (deskew, despeckle) Printing capabilities from VB The ability to add text to image, e.g. time / date Nice to have:
3
1467
by: D.Hering | last post by:
General: How do I download a page's data from a clean url. Specific: I'm using PyQt's QHttp and QUrl classes for requests and acquiring the response, but I can't figure out how to access a page's data without knowing the file of the url's path. For instance http://kde.org Thanks, -Dieter
0
1111
by: Christopher | last post by:
How can I make a vc++ project erase its $(OutDir) upon using the clean command? I tryed Properties->Configuration Properties->General->Extensions to Delete on Clean Add $(ObjDir) And it didn't work. Of course I know it is asking for extentions and not a
10
4580
by: Simon | last post by:
As title. How to clean out VSWebCache? Any good way to do that? Thanks.
0
8944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9445
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9234
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.