472,354 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

Similar topics

7
by: Martin Bless | last post by:
IMHO PythonWin is great help in developing. How can I do something like: if detect("running on PythonWin"): pass # fake arguments ... else: "proceed normal"
1
by: Henrik Weber | last post by:
Hi. I have tried to add pychecker as an extension to pythonwin. Now I can have pychecker check the source file that is currently open in the editor with a single keypress. If someone is...
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...
3
by: tkpmep | last post by:
I have a Python program that collects user input using msg = "Enter the full path and name of the file to be processed: " answer = raw_input(msg) If I run it in IDLE, the question is splashed...
2
by: Joseph Turian | last post by:
Hi, What is the safest manner to extend search path for modules, minimizing the likelihood of shooting oneself in the foot? The system (which includes scripts and their shared modules) may be...
1
by: rodrigostrauss | last post by:
Having the following code: ==== Module1.py ==== import logging def X(): logging.error('test') If I import it into PythonWin console and call X(), the error message is not printed. If I do...
2
by: leegold | last post by:
Hi, I run a script in PythonWin and obviously some sort of an error occurs in the script and PythonWin closes. No warning, no error message just closes. I definitely know the line of code that...
0
by: Martin P. Hellwig | last post by:
Hello all, I had some troubles in the past how to arrange my packages and modules, because I usually don't develop my stuff in the Lib\site-packages directory I have some troubles when importing...
4
by: sterling | last post by:
I'm curious as to why the difference between IDLE and pythonWin when using win32com. opening an excel file, i've attempted to grab the chart information out of the file. commands like co =...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

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.