469,568 Members | 1,455 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

How do I edit a PythonWin path to import custom built modules???

Hi Guys,

I've been using the following IDE,

"Pythonwin - Python IDE and GUI Framework for Windows.

Copyright 1994-2001 Mark Hammond "

With respect to my work, I had created my own modules (.py files) in
drives and folders other than the python root. I know that if I need to
import these modules, I need to specify the path of the directory where
I've put my modules. I've tried the "Edit Python Path" sub menu in the
menu "Tools" of PythonWin, but I could not add a new path i.e.-
D:\xxxx\xxxx\xxxx\ATS.

Could any one please let me know how could I add a new path to access
my own modules.

Thanks in advance,
Mohan Swaminathan.

Dec 11 '06 #1
17 5007
mohan wrote:
I had created my own modules (.py files) in
drives and folders other than the python root.
Probably easiest if you keep them all in one place. Then add that
"place" to your path by going into Control
Panel|System|Advanced|Environment Variables and adding the path to the
path variable.

Hope that helps.

rd

Dec 11 '06 #2

BartlebyScrivener wrote:
mohan wrote:
I had created my own modules (.py files) in
drives and folders other than the python root.

Probably easiest if you keep them all in one place. Then add that
"place" to your path by going into Control
Panel|System|Advanced|Environment Variables and adding the path to the
path variable.

Hope that helps.

rd
Thanks rd,

I tried your advice, by adding a new path to the "System Variable"
section. It still does not work. I don't understand how could PythonWin
interpreter would look for new folders when we have not yet updated the
path in the interpreter. I'm sorry I might be mising something here as
i'm not too familiar with these things.

Any further ideas??

Regards,
Mohan.

Dec 12 '06 #3
mohan ha escrito:
I had created my own modules (.py files) in
drives and folders other than the python root.
I tried your advice, by adding a new path to the "System Variable"
section. It still does not work. I don't understand how could PythonWin
There was an error in a previous post, you should create a variable
called PYTHONPATH, not change the system PATH.
Or, group your modules into packages and put them below
lib\site-packages.

--
Gabriel Genellina

Dec 12 '06 #4

Gabriel Genellina wrote:
>
There was an error in a previous post, you should create a variable
called PYTHONPATH, not change the system PATH.
Or, group your modules into packages and put them below
lib\site-packages.
Perhaps your way works also, but I have no PythonPath defined in system
variables on Windows XP.

I keep my Python scripts and modules in d:\Python. I added d:\Python to
the Path variable and I can call and import the scripts and modules
from anywhere I please.

I'm pretty sure that the ActiveState distribution of Python adds its
paths to the Path variable also.

rd

Dec 12 '06 #5
BartlebyScrivener wrote:
Perhaps your way works also, but I have no PythonPath defined in system
variables on Windows XP.

I keep my Python scripts and modules in d:\Python. I added d:\Python to
the Path variable and I can call and import the scripts and modules
from anywhere I please.
Python does *not* use the Path when searching for modules; sys.path is
initialized based on the contents of PYTHONPATH, the location of the
Python executable (or PYTHONHOME), some heuristics, and certain registry
entries. there used to be a page about this on python.org, but it seems
to have disappeared; here's the SVN copy:

https://svn.python.org/www/trunk/pyd...ws/registry.ht

</F>

Dec 12 '06 #6

Fredrik Lundh wrote:
Python does *not* use the Path when searching for modules; sys.path is
initialized based on the contents of PYTHONPATH, the location of the
Python executable (or PYTHONHOME), some heuristics, and certain registry
entries.
Now I'm stumped. Unless it's heuristics. The registry entry for
PythonPath does NOT reference the location of my Python scripts
(d:/Python). And Python is installed in the usual place on C:\Python24.
The only place that I can see where I've told it the location of my
scripts is in the Path variable.

I have no doubt that you're correct. Just confused as usual.

rd

Dec 13 '06 #7
At Wednesday 13/12/2006 10:10, BartlebyScrivener wrote:
Python does *not* use the Path when searching for modules; sys.path is
initialized based on the contents of PYTHONPATH, the location of the
Python executable (or PYTHONHOME), some heuristics, and certain registry
entries.

Now I'm stumped. Unless it's heuristics. The registry entry for
PythonPath does NOT reference the location of my Python scripts
(d:/Python). And Python is installed in the usual place on C:\Python24.
The only place that I can see where I've told it the location of my
scripts is in the Path variable.

I have no doubt that you're correct. Just confused as usual.
import sys
print sys.path

and see what's there.
--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ˇgratis!
ˇAbrí tu cuenta ya! - http://correo.yahoo.com.ar
Dec 14 '06 #8

Gabriel Genellina wrote:
>
import sys
print sys.path
and see what's there.
Yup. Did that before. That's what I mean. The d:\\python is there and
it doesn't come from the PythonPath in my windows registry. Maybe it
scans for any directory with python in the name?

['', 'C:\\WINDOWS\\system32\\python24.zip', 'd:\\python',
'C:\\Python24\\DLLs', 'C:\\Python24\\lib',
'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk',
'C:\\Python24\\Lib\\site-packages\\pythonwin', 'C:\\Python24',
'C:\\Python24\\lib\\site-packages',
'C:\\Python24\\lib\\site-packages\\win32',
'C:\\Python24\\lib\\site-packages\\win32\\lib',
'C:\\Python24\\lib\\site-packages\\wx-2.7.1-msw-ansi']

rd

Dec 14 '06 #9
BartlebyScrivener wrote:

Yup. Did that before. That's what I mean. The d:\\python is there and
it doesn't come from the PythonPath in my windows registry.
what do you get if you do:
python -S
....
>>import sys
sys.path
and then
>>import site
sys.path
?

</F>

Dec 14 '06 #10

BartlebyScrivener wrote:
Yup. Did that before. That's what I mean. The d:\\python is there and
it doesn't come from the PythonPath in my windows registry. Maybe it
scans for any directory with python in the name?
Do you have any *.pth files in the C:\Python24 directory?

....
jay

Dec 14 '06 #11
Fredrik Lundh wrote:
what do you get if you do:
python -S
...
>>import sys
sys.path
['', 'C:\\WINDOWS\\system32\\python24.zip', 'd:\\python',
'C:\\Python24\\DLLs', 'C:\\Python24\\lib',
'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 'C:\
\Python24']
and then
>>import site
sys.path
['d:\\python', 'C:\\WINDOWS\\system32\\python24.zip',
'C:\\Python24\\DLLs', 'C:\\Python24\\lib',
'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 'C:\\Pyt
hon24', 'C:\\Python24\\lib\\site-packages',
'C:\\Python24\\lib\\site-packages\\win32',
'C:\\Python24\\lib\\site-packages\\win32\\lib',
'C:\\Python24\\lib\\site-packa
ges\\Pythonwin', 'C:\\Python24\\lib\\site-packages\\wx-2.7.1-msw-ansi']

rd

Dec 14 '06 #12
jay graves wrote:
>
Do you have any *.pth files in the C:\Python24 directory?
No.

Dec 14 '06 #13
BartlebyScrivener wrote:
>what do you get if you do:
>>python -S
...
>>>import sys
sys.path

['', 'C:\\WINDOWS\\system32\\python24.zip', 'd:\\python',
'C:\\Python24\\DLLs', 'C:\\Python24\\lib',
'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 'C:\
\Python24']
since it appears *after* the ZIP archive, but before the standard path,
it should be either a registry setting or a custom-built interpreter
(is this an ActiveState build?). or maybe you could get this effect if
you have a copy of "python.exe" in d:\python, but I'm pretty sure that
the directory should end up at the *end* of the path in that case.

have you searched the *entire* registry for the "PythonCore" key?
(python looks under HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER)

what's sys.prefix and sys.exec_prefix set to on your machine, btw?

</F>

Dec 14 '06 #14
Fredrik Lundh wrote:
is this an ActiveState build?
Yes, I think I mentioned it further up the thread.
what's sys.prefix and sys.exec_prefix set to on your machine, btw?
'C:\\Python24'

No big deal. I always just assumed that it found my scripts via the
path variable. As long as it finds them. I'm happy.

But you got me thinking. I just did the commands you suggested on my
laptop, after installing python.org 2.5. With 'd:\python' in the path
environmental variable there also, it does NOT appear when I do plain
old:
>>>sys.path
but does appear when I import site first.

rd

Dec 14 '06 #15
Fredrik Lundh wrote:
>
have you searched the *entire* registry for the "PythonCore" key?
(python looks under HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER)
I found it in the Scripts key! I was searching on PythonPath before.
Sorry. Thank you for the enlightenment.

rd

Dec 14 '06 #16

BartlebyScrivener wrote:
Gabriel Genellina wrote:

import sys
print sys.path
and see what's there.

Yup. Did that before. That's what I mean. The d:\\python is there and
it doesn't come from the PythonPath in my windows registry. Maybe it
scans for any directory with python in the name?

['', 'C:\\WINDOWS\\system32\\python24.zip', 'd:\\python',
'C:\\Python24\\DLLs', 'C:\\Python24\\lib',
'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk',
'C:\\Python24\\Lib\\site-packages\\pythonwin', 'C:\\Python24',
'C:\\Python24\\lib\\site-packages',
'C:\\Python24\\lib\\site-packages\\win32',
'C:\\Python24\\lib\\site-packages\\win32\\lib',
'C:\\Python24\\lib\\site-packages\\wx-2.7.1-msw-ansi']

rd
Hi rd,

To revert back to my question, I wanted to add a new path to my
PythonWin IDE to access modules which are in folders other than normal
python paths. Here, I need to put my modules in different folders
since it is a request of the user. I tried to create a new PYTHONPATH
in the environmental variables section, which did not work .

So, is there any way where I can temporarily append the new path/s,
where the PythonWin interpreter would look during run time and discard
after the interpreter is closed.

For example, my main program "ATS.py" will be put in the folder
D:\\dSPACE\ATS\ and my modules will be put in other folders inside the
folder ATS, D:\\dSPACE\ATS\ Level Regulation, D:\\dSPACE\ATS\ Curve
Detection and so on.

So, I would like to tell the interpreter to look in to these folders to
import the modules.

Is that possible???

Regards,
Mohan

Dec 15 '06 #17
At Friday 15/12/2006 06:46, mohan wrote:
>To revert back to my question, I wanted to add a new path to my
PythonWin IDE to access modules which are in folders other than normal
python paths. Here, I need to put my modules in different folders
since it is a request of the user. I tried to create a new PYTHONPATH
in the environmental variables section, which did not work .
You can do that directly inside PythonWin, using the Tools menu.
>So, is there any way where I can temporarily append the new path/s,
where the PythonWin interpreter would look during run time and discard
after the interpreter is closed.
You could modify sys.path at runtime, appending directories if
needed. But the package solution below is much better.
>For example, my main program "ATS.py" will be put in the folder
D:\\dSPACE\ATS\ and my modules will be put in other folders inside the
folder ATS, D:\\dSPACE\ATS\ Level Regulation, D:\\dSPACE\ATS\ Curve
Detection and so on.

So, I would like to tell the interpreter to look in to these folders to
import the modules.
First, remove all spaces from directory names. Then make them normal
packages (an empty __init__.py may be enough) so you can write, in ATS.py:

from LevelRegulation import whatever
from CurveDetection.MyModuleName import MyClass

etc.
--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ˇgratis!
ˇAbrí tu cuenta ya! - http://correo.yahoo.com.ar
Dec 15 '06 #18

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Martin Bless | last post: by
1 post views Thread by Henrik Weber | last post: by
4 posts views Thread by r.e.s. | last post: by
3 posts views Thread by tkpmep | last post: by
2 posts views Thread by Joseph Turian | last post: by
2 posts views Thread by leegold | last post: by
reply views Thread by Martin P. Hellwig | last post: by
4 posts views Thread by sterling | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.