* Jive Dadson:
Okay, with your help I've figured it out. Instructions are below, but
read the caveat by Ben Fenny in this thread. All this stuff is good for
one default version of Python only. The PYTHONPATH described below, for
example, cannot specify a version number. Yes, that's a pain in the
butt, but there's no way around it. If you switch versions, you may
have to delete all the .pyc files that will show up in the module
folders. Python ought to check them to see if they are valid, but I do
not know if it does so.
These instructions are for MS Windows.
1) Create your modules folder. Let's say it's named "Modules." The
documentation calls it a "package."
2) In an explorer window or on the desktop, right click on My Computer,
and select Properties.
3) Select the Advanced tab, and click on Environment Variables near the
bottom.
4) Look for an environment variable named PYTHONPATH.
a) If you do not find one, create one using the New button(s). I
don't know if it has to be in User Variables or System Variables. To
save time experimenting, I just put one in both. For the value, put the
full path of the folder Modules.
The User variables /override/ the System variables for a given user. The System
variables provide defaults for all users. One notable exception is PATH, where
the User PATH items are appended to the System PATH.
Anyways, with many items in a variable like PATH it can be impractical to use
Windows' functionality, which presents it all on one line, which for a PATH with
many items can be exceeding long -- like a many thousand characters[1] line.
So for your convenience, below is a little Windows app (as an HTML application,
it's just some HTML and VBScript and CSS) that presents the user PATH items one
per line in a Notepad-like window. It should be no problem modifying it to
instead edit PYTHONPATH, or even a choice of environment variable. As my late
father used to say, when you don't have a tool, you make it.
Maybe now I should recode this in Python. But on the other hand, one shouldn't
spend time fixing what works. So ... enjoy! :-)
Note: it's crucial to use [.HTA] filename extension.
Also, it's quite possible that this doesn't work in Windows Vista (at least not
without configuration of Windows), but it works in XP and earlier.
<code file="userpath.hta">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<!-- If this works, then it was written by Alf P. Steinbach.
Otherwise it's someone impersonating me.
And yes, if you've seen a comment like this before: I/he stole it. :-) -->
<html>
<head>
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta http-equiv="MSThemeCompatible" content="yes">
<hta:application scroll="no"/>
<title>Simple user-environment %path% editor</title>
<style>
body { margin: 0px; padding: 0px; }
#menuArea
{
width: 100%; height: 1.8em; white-space: nowrap; padding-top:
2px;
background: #E0E0E0;
}
#clientArea
{
width: 100%; position: absolute; top: 1.8em; bottom: 0;
}
#pathEditor
{
display: inline-block;
width: 100%; height: 100%;
border: 0;
position: absolute; top: 0;
overflow: scroll;
}
</style>
<script type="text/vbscript" language="vbscript">
option explicit
dim wshShell
dim wshUserEnv
dim originalText
sub loadText
pathEditor.innerText = replace( wshUserEnv( "PATH" ), ";",
vbNewline)
end sub
sub saveText
dim text
dim button
text = pathEditor.innerText
text = replace( text, vbNewLine, ";" )
button = MsgBox( _
text, vbYesNo + vbQuestion, "Save this as new %path%
value?" _
)
if button = vbYes then wshUserEnv( "PATH" ) = text
end sub
sub onBtnLoad
loadText
end sub
sub onBtnLoadOriginal
pathEditor.innerText = originalText
end sub
sub onBtnSave
saveText
end sub
sub onLoaded
set wshShell = createObject( "WScript.Shell" )
set wshUserEnv = wshShell.environment( "USER" )
loadText
originalText = pathEditor.innerText
MsgBox _
"Type one path per line (no semicolons)", _
vbInformation, _
"How to use:"
end sub
</script>
</head>
<body onload="onLoaded">
<div id="menuArea">
<button onClick="onBtnLoad">Load current</button>
<button onClick="onBtnLoadOriginal">Reload original</button>
<button onClick="onBtnSave">Save as current ...</button>
</div>
<div id="clientArea">
<textarea id="pathEditor" wrap="off">
</textarea>
</div>
</body>
</html>
</code>
b) If there's already a PYTHONPATH, Edit it, adding a semi-colon and
the full path of folder Module to the end.
5) Put your module folders into the folder Module.
6) (Here's a really arcane bit.) Into each module folder, put a file
named __init__.py. It will be executed when you load the module. It
can be empty, but it has to be there or else the module folder will be
ignored.
Cheers & hth.,
- Alf
Notes:
[1] Windows XP and I believe also Vista places a limit of about 8 KiB on the
length of any environment variable.
--
http://mail.python.org/mailman/listinfo/python-list