469,366 Members | 2,286 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

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

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
Feb 3 '07 #1
9 2103
Stef Mientki <S.**************@mailbox.kun.nlwrites:
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)
Do you mean something like that?
>>import some_module
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named some_module
>>import sys
sys.path.append("..")
import some_module
http://docs.python.org/tut/node8.htm...00000000000000

--
HTH,
Rob
Feb 4 '07 #2
Do you mean something like that?
>
>>>import some_module
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named some_module
>>>import sys
sys.path.append("..")
import some_module
Rob,
thank you very much,
that's exactly what I want.
(Why is the obvious so often invisible to me ;-)

cheers,
Stef Mientki
Feb 4 '07 #3
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
Feb 4 '07 #4
Jussi Salmela wrote:
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?
No, I run Python, embedded from within a Delphi program.
>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.
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
Feb 4 '07 #5
Through "My computer" | properties | advanced | Environment Variables"
you have to reboot.
The best overall solution is the one where you modify sys.path to add
your own custom paths, 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/d....mspx?mfr=true

Feb 4 '07 #6
Inca wrote:
>Through "My computer" | properties | advanced | Environment Variables"
you have to reboot.

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/d....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
Feb 4 '07 #7
Stef Mientki wrote:
>Do you mean something like that?
>>>>import some_module
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named some_module
>>>>import sys
sys.path.append("..")
import some_module
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

Feb 4 '07 #8
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
>
Feb 4 '07 #9
En Sat, 03 Feb 2007 14:25:31 -0300, Stef Mientki
<S.**************@mailbox.kun.nlescribió:
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.

--
Gabriel Genellina

Feb 5 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Rami A. Kishek | last post: by
2 posts views Thread by Eric Wichterich | last post: by
4 posts views Thread by r.e.s. | last post: by
8 posts views Thread by Tero Pihlajakoski | last post: by
3 posts views Thread by D Denholm | last post: by
10 posts views Thread by sushant.sirsikar | last post: by
reply views Thread by Michael Yanowitz | last post: by
4 posts views Thread by mhearne808[insert-at-sign-here]gmail[insert-dot-he | last post: by
1 post views Thread by Aljosa Mohorovic | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.