473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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 2217
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Rami A. Kishek | last post by:
Hi, I would really appreciate help on this from all ye Win-oriented people. I have been using python under Linux for quite a while, know little about windows. I just upgraded my Python on WinME...
2
by: Eric Wichterich | last post by:
Hello Pythonistas, I am trying to get certain (self-written) libraries imported into my scripts using statements like "from library import function.py". But they are not being found. I...
4
by: r.e.s. | last post by:
I have no PYTHONPATH nor any other python-related environment variables, yet everything seems fine. (I'm using PythonWin with winxp.) As long as modules are loaded through PythonWin, is...
8
by: Tero Pihlajakoski | last post by:
Hi, I've been experimenting on embedding Python to a C software, and ran into a little problem with PYTHONPATH (I'm running on linux). Here's the deal: When trying to call...
3
by: D Denholm | last post by:
I recently installed Python 2.2 on my WinXP box. I am having problems figuring out how to create the PYTHONPATH correctly. I went to the WinXP SystemProperties > Advanced > Environment...
10
by: sushant.sirsikar | last post by:
Hi, I am using Linux env.I set the PYTHONPATH using import sys sys.path.append(----) But we i close python and start again i is not showing my new entry in PYTHONPATH. Can anyone help me to...
0
by: Michael Yanowitz | last post by:
Hello: Someone on my team tried out installing my Python code and found that setting PYTHONPATH does not work, but setting PATH environment variable works the way PYTHONPATH should. Is that how...
4
by: mhearne808[insert-at-sign-here]gmail[insert-dot-he | last post by:
I'm missing something major here. I'm trying to add a directory to my python path using the PYTHONPATH environment variable, and it's being ignored by the Python interactive shell. Below is a...
1
by: Aljosa Mohorovic | last post by:
i have a working MySQLdb module (/usr/lib/python2.4/site-packages/ MySQL_python-1.2.2-py2.4-linux-i686.egg), using it without problems. "clean shell" after login: python -c "import MySQLdb"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.