PYTHONPATH or any other way to set seachpath (winXP) ?

S

Stef Mientki

Is it possible to change the searchpath for modules on the flight,
under winXP ?
Most preferred is some command to extend the searchpath.
(the environment variable PYTHONPATH needs a reboot)

thanks,
Stef Mientki
 
S

Stef Mientki

Do you mean something like that?
Traceback (most recent call last):
Rob,
thank you very much,
that's exactly what I want.
(Why is the obvious so often invisible to me ;-)

cheers,
Stef Mientki
 
J

Jussi Salmela

Stef Mientki kirjoitti:
Is it possible to change the searchpath for modules on the flight,
under winXP ?
What do you mean by *on the flight*: inside IDLE? using the command line?
Most preferred is some command to extend the searchpath.
(the environment variable PYTHONPATH needs a reboot)
No, it doesn't. PYTHONPATH can be updated somewhere in the environment
options (sorry: I've got a Finnish language XP version, so I don't
remember the exact terms) and the new path comes in effect immediately
i.e. the launches after that see the new definition.

That way of changing the PYTHONPATH is a little difficult, though. In
command line usage i.e. CMD.EXE I have been using these kinds of bat
files to alternate between versions 2.4 and 2.5 of Python. (These were
suggested earlier by someone in this group I think):
===
Py24.bat (Py25.bat has Python25 instead of Python24 in it)
===
@echo off
if .%1.==.. goto NODEV
set DEMOHOME=%1
goto CONT
:NODEV
set DEMOHOME=C:
:CONT
set PYTHONHOME=%DEMOHOME%\Python24
set PYTHONPATH=%PYTHONHOME%;
set PYTHON=%PYTHONHOME%\python.exe
set PYTHONW=%PYTHONHOME%\pythonw.exe
set PATH=%PYTHONHOME%;%PATH%

===
Py.bat (to launch Python)
===
"%PYTHON%" "%1.py" "%2" "%3" "%4" "%5" "%6" "%7" "%8" "%9"
thanks,
Stef Mientki

HTH,
Jussi
 
S

Stef Mientki

Jussi said:
Stef Mientki kirjoitti:
What do you mean by *on the flight*: inside IDLE? using the command line?

No, I run Python, embedded from within a Delphi program.
No, it doesn't. PYTHONPATH can be updated somewhere in the environment
options (sorry: I've got a Finnish language XP version, so I don't
remember the exact terms) and the new path comes in effect immediately
i.e. the launches after that see the new definition.
Through "My computer" | properties | advanced | Environment Variables"
you have to reboot.
But as I remember well there should be a way, (through the registry or DOS-box ?)
but I don't want to mess in the registry,
I want to keep my application portable.
But the suggestion of Rob, looks perfect.

thanks anyway,
Stef Mientki
 
I

Inca

S

Stef Mientki

Inca said:
The best overall solution is the one where you modify sys.path to add
your own custom paths,
I agree, specially in my situation that is the best solution.

however Jussi is right in that you do not need
to reboot. You have to restart any applications that relies on using
the updated environment variables (in your case the Delphi program):

http://www.microsoft.com/resources/...ocs/en-us/environment_variables.mspx?mfr=true
I think the problem comes from the Delphi interface,
both Idle and PyScripter reflect a change PYTHONPATH after a restart.
But my Delphi program needs a reboot :-(
I'll ask around in the Python4Delphi newsgroup.

cheers,
Stef Mientki
 
R

Ron Adam

Stef said:
Rob,
thank you very much,
that's exactly what I want.
(Why is the obvious so often invisible to me ;-)

cheers,
Stef Mientki

Just a note, If you run the module from different location, it may not always
work.

The '..' is relative to the location you are running the module from, the
current directory, and not relative to the location of the module is at.

It won't be a problem for you if you can be sure the module is always ran from
the location it is at.

Cheers,
Ron
 
S

Stef Mientki

Just a note, If you run the module from different location, it may not
always work.

The '..' is relative to the location you are running the module from,
the current directory, and not relative to the location of the module is
at.
thanks for the tip Ron,
I didn't realized ".." was literal ;-)
so I've changed my application, so it inserts the absolute path.

cheers,
Stef
 
G

Gabriel Genellina

En Sat, 03 Feb 2007 14:25:31 -0300, Stef Mientki
Is it possible to change the searchpath for modules on the flight,
under winXP ?
Most preferred is some command to extend the searchpath.
(the environment variable PYTHONPATH needs a reboot)

PYTHONPATH is used to build the initial contents of sys.path, which is the
actual list of directories searched. It's a standard list object so you
can modify it easily.
 

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

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,270
Latest member
TopCryptoTwitterChannels_

Latest Threads

Top