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

W

wen

on my system(win2k server, python 2.3.5),['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
 
B

bruno modulix

wen said:
on my system(win2k server, python 2.3.5),

['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
 
W

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.
 
P

poyol

wen said:
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 .....
 
W

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.
 
S

Steve Holden

apa said:
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
 
J

John Machin

wen said:
on my system(win2k server, python 2.3.5),

['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>)
 
J

James Sungjin Kim

Steve said:
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
 
S

Steve Holden

James said:
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
 
P

Peter Hansen

Steve said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top