469,312 Members | 2,496 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

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

wen
on my system(win2k server, python 2.3.5),
import sys
print sys.path

['C:\\', 'C:\\WINNT\\system32\\python23.zip',
'C:\\Python23\\lib\\site-packages\\Pythonwin',
'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\\PyMOL\\modules']

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

any help would be appreciated.

with my kind regards,
Wen
Aug 18 '05 #1
10 12434
apa
You can do it this way:

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

Alejandro

Aug 18 '05 #2
wen wrote:
on my system(win2k server, python 2.3.5),
import sys
print sys.path

['C:\\', 'C:\\WINNT\\system32\\python23.zip',
'C:\\Python23\\lib\\site-packages\\Pythonwin',
'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\\PyMOL\\modules']

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

any help would be appreciated.


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 'o****@xiludom.gro'.split('@')])"
Aug 18 '05 #3
wen
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" <ap******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
You can do it this way:

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

Alejandro

Aug 18 '05 #4

wen wrote:
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.


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

Aug 18 '05 #5
wen
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" <ap******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
You can do it this way:

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

Alejandro

Aug 18 '05 #6
apa wrote:
You can do it this way:

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

Alejandro

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/

Aug 18 '05 #7
wen wrote:
on my system(win2k server, python 2.3.5),
import sys
print sys.path


['C:\\', 'C:\\WINNT\\system32\\python23.zip',
'C:\\Python23\\lib\\site-packages\\Pythonwin',
'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\\PyMOL\\modules']

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

any help would be appreciated.

with my kind regards,
Wen


cat clpyaibot.log
* sys.path is instance of <list>.
* "C:\Python23\Pmw\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>.addinto ... not found
* checking plausible alternatives ...
* <list>.append(<object>)
* <list>.insert(<index>, <object>)
Aug 18 '05 #8
Steve Holden wrote:
sys.path.append(r"C:\Temp")


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
Aug 19 '05 #9
James Sungjin Kim wrote:
Steve Holden wrote:
sys.path.append(r"C:\Temp")

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


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 "environment 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/

Aug 19 '05 #10
Steve Holden wrote:
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.


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

-Peter
Aug 19 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Egor Bolonev | last post: by
2 posts views Thread by Steven Burn | last post: by
34 posts views Thread by Reinhold Birkenfeld | last post: by
1 post views Thread by William Stacey [MVP] | last post: by
6 posts views Thread by bukzor | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.