Re: [Tutor] Wrong version of Python being executed

2007-11-19 Thread Alan Gauld
"Tony Cappellini" <[EMAIL PROTECTED]> wrote

> So I've changed the association from the 2.3 icon to the 2.5 icon, 
> and
> now I can run my script from the command line as follows
>
> python script.py, and the correct version of Python is invoked.
>
> This is very disturbing because it means the path or other env vars
> have no control (or very little) as to which version of Python is
> invoked.

There are multiple mechanisms.
The PATH and env vars should take precedence inside a DOS
box but from Explorer or from Start-Run its the registry settings
that matter.

> How do other people deal with having multiple versions of Python on
> their system, and not run into this issue??

By using one under cygwin and the other under Windows.
I currently have 2.5 installed in cygwin but 2.4 in Windows...
(and 2.5 and 2.3 installed in MacOS - and 2.2 on Linux!)

Alan G 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-19 Thread Tony Cappellini
I've found something interesting regarding this issue.

I went to Windows Explorer, Tools,Folder Options, File Types and
noticed that there are two different icons associated with .PY files.
The Icon for Python 2.5 is easy to recognize as compared with the icon
for Python 2.3.

So I've changed the association from the 2.3 icon to the 2.5 icon, and
now I can run my script from the command line as follows

python script.py, and the correct version of Python is invoked.

This is very disturbing because it means the path or other env vars
have no control (or very little) as to which version of Python is
invoked.


How do other people deal with having multiple versions of Python on
their system, and not run into this issue??



On Nov 10, 2007 6:16 PM, Kent Johnson <[EMAIL PROTECTED]> wrote:
>
> Tony Cappellini wrote:
> > When I run this python script, the following exception is thrown,
> > implying that it is being executed with Python 2.3
> > So I've added this print statement to the main function, which shows
> > the logging module is being imported from the Python 2.3 directory
> >
> > print"\nlogging.__file__ = %s" % logging.__file__
> >
> > logging.__file__ = C:\Python23\lib\logging\__init__.pyc
> >
> >
> >
> > Traceback (most recent call last):
> >   File "c:\Project\myscript.py", line 584, in
> > ?
> > main(sys.argv)
> >   File "c:\Project\myscript.py", line 518, in
> > main
> > logging.basicConfig(level=config.verbosity,format='%(message)s')
> > TypeError: basicConfig() takes no arguments (2 given)
> >
> >
> > The really odd thing is when I bring up the python interpreter at the
> > same command prompt where i ran the script above,
> > Python 2.5 is invoked, as seen by
> >
> >
> > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
> > (Intel)] on win32
> > Type "help", "copyright", "credits" or "license" for more information.
>  import sys
>  sys.version
> > '2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)]'
> >
> >
> > How is it that running a script invokes Python 2.3, but running the
> > interpreter without the script invoked Python 2.5?
>
> A couple of possibilities...
> Is there a #! line at the start of the script that specifies Python 2.3
> (I'm not sure if those work in windows though...)
>
> How do you run the script? If you double-click it, perhaps the file
> association with .py files is to Python 2.3?
>
> Conceivably the Python 2.5 module path is incorrect and imports the
> wrong module. What happens if you import logging from the interpreter
> prompt and print its file? What do you get if you print sys.path from
> the interpreter?
>
> HTH,
> Kent
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-12 Thread Tony Cappellini
Date: Mon, 12 Nov 2007 09:14:05 -
From: "Alan Gauld" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Wrong version of Python being executed
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
   reply-type=original



>>Umm, have you rebooted? Probably an obvious step but I don't
many times
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-12 Thread Martin Walsh
Alan Gauld wrote:
> "Tony Cappellini" <[EMAIL PROTECTED]> wrote
> 
>> I have to switch between 2.3 and 2.5, so to make it easy, I use an
>> environment variable called CURRENT_PYTHON.
>> (someone on this list or the wxPython list told me I should NOT use
>> PYTHONPATH and modify it the way I am using CURRENT_PYTHON)
>>
>> CURRENT_PYTHON=C:\PYTHON2X
>> path=%CURRENT_PYTHON%
>> (The existing path isn't shown, only for brevity)
> 
>> Note, these are entered in Ctrl Panel, System environment variables,
>> NOT at the command line.

That seems like a perfectly rational approach, and good advice.

Unfortunately I don't have a windows machine to test/confirm at the
moment, but IIRC you can set both user-space and system-wide environment
variables this way. I think PATH is special, in that user-space PATH is
appended to the *end* of the system-wide PATH, where other vars set in
user-space override the system defaults? Is it possible you have
python23 in your system-wide path, and you've edited user-space path to
include %CURRENT_PYTHON%?

Regardless, as a test you might try to add C:\Python25 to the front of
your system-wide PATH temporarily. This should aid in diagnosing a
simple PATH lookup problem. But, I'm stumped also. I don't know of any
reason why you would be seeing this behavior if you are invoking python
in a consistent way.

> 
> Umm, have you rebooted? Probably an obvious step but I don't
> think environment vars get reset in real time. They didn't used
> to on NT but that may have changed in W2K or XP... I haven't
> checked in a while.

I believe that this has changed somewhat, where the environment is read
at program startup. So the env is not refreshed until you close and
re-launch the program in question (in this case 'cmd'). Not sure how
windows explorer is effected, which may require a logoff/logon.  But,
again I don't have a windows machine available to confirm, so take that
for what it's worth. It's not going to hurt to reboot, that's for certain.

> 
> Othewise I'm as stumped as you.
> 
> Alan G 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-12 Thread Alan Gauld

"Tony Cappellini" <[EMAIL PROTECTED]> wrote

> I have to switch between 2.3 and 2.5, so to make it easy, I use an
> environment variable called CURRENT_PYTHON.
> (someone on this list or the wxPython list told me I should NOT use
> PYTHONPATH and modify it the way I am using CURRENT_PYTHON)
>
> CURRENT_PYTHON=C:\PYTHON2X
> path=%CURRENT_PYTHON%
> (The existing path isn't shown, only for brevity)

> Note, these are entered in Ctrl Panel, System environment variables,
> NOT at the command line.

Umm, have you rebooted? Probably an obvious step but I don't
think environment vars get reset in real time. They didn't used
to on NT but that may have changed in W2K or XP... I haven't
checked in a while.

Othewise I'm as stumped as you.

Alan G 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-11 Thread Tony Cappellini
Message: 2
Date: Sun, 11 Nov 2007 16:57:01 -0600
From: Martin Walsh <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Wrong version of Python being executed
To: Tutor Python 
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1


>>My initial thought based on your description was that python2.5 is
being invoked with PYTHON* env
>>vars from a previous install, or some site module weirdness.

Not sure how the "previous install" surfaced, but I installed all
python installations and packages on my computer.

I have to switch between 2.3 and 2.5, so to make it easy, I use an
environment variable called CURRENT_PYTHON.
(someone on this list or the wxPython list told me I should NOT use
PYTHONPATH and modify it the way I am using CURRENT_PYTHON)

CURRENT_PYTHON=C:\PYTHON2X
path=%CURRENT_PYTHON%
(The existing path isn't shown, only for brevity)

Note, these are entered in Ctrl Panel, System environment variables,
NOT at the command line.


>>But, the fact that running python.exe with it's full path corrects the issue,
>>seems to indicate a problem with your PATH, rather than any python
Yes, my conclusion also, but what is wrong with the path?
I've posted the contents of PATH in the original email or one of the
subsequent ones.

>>Would the following be an accurate description of the behavior?

>>assuming:
>>- you run inside a fresh 'cmd' console each time (typing 'cmd' at the
>>run dialog, or similar), to be sure there is no app environment kruft

correct-

>>- the current working directory doesn't contain any programs, scripts or
>>possibly links that could interfere (preferably an empty path)

Not that I can see

>>- you don't have any PYTHON* environment vars set (including PYTHONSTARTUP)

No- see for yourself. No python anything variables.
C:\Documents and Settings\z30032as>set python
Environment variable python not defined

>>you observe:
>>- when you type 'python' (only 'python') at the prompt, you get
>>python2.5 interactively

Correct

>>- when you use the form 'python script.py', the script is run with
>>python2.3 (can you verify with sys.version?) with sys.path appropriate
>>for 2.3

Correct

>>- when you use the form 'c:\python25\python.exe script.py', the script
>>is executed with python2.5 and you have the correct sys.path (for 2.5)
Correct

>>I wouldn't think so, but I suppose it is possible. I believe all the
>>pertinent registry keys are store under
>>"HKLM\Software\Python\Pythoncore\", so you could have a look.

Already did. There IS a PYTHONPATH entry for each of the 3 versions of
Python I have installed.
They are all identical, with the exception of the last 2 digits for
the Python version.
This looks ok to me. No other rogue entries of PYTHONPATH were found
in the registry.

>>BTW, are you using an alternate distribution of python (ex.
>>ActiveState), or the standard python.org version?

No. I always use the regular Python.Org distributions. I never
understood what was so special about ActiveState anyway.
I;d rather have full control of my installs, and all the packages.
Although, at this point, I'm not in control over what is happening
with my path ;-)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-11 Thread Alan Gauld
"Martin Walsh" <[EMAIL PROTECTED]> wrote

 Try using the full path to python, just to be sure: 
 c:\python25\python
 script.py -- do you get the same behavior?
>> This works just fine- I would expect it to.
>
> Actually, I would have expected the opposite.

Me too.

> Though this still doesn't explain why you get python2.5 
> interactively,
> and python2.3 when running a script -- perhaps I'm still unclear 
> what
> you are seeing. Would the following be an accurate description of 
> the
> behavior?
>
> assuming:
> - you run inside a fresh 'cmd' console each time (typing 'cmd' at 
> the
> run dialog, or similar), to be sure there is no app environment 
> kruft

This is very important. If you just type python at the Run
dialog it uses a different algorithm to find the exe than if
you type python at a DOS prompt inside a CMD window.
Its the second algorithm that is used if you type
python foo.py at a cmd prompt but the first that
is used if you double click foo.py within explorer
(actually that could even be a different one again!)
or type python foo.py in the Run dialog.

> fix. BTW, are you using an alternate distribution of python (ex.
> ActiveState), or the standard python.org version?

That *shouldn't* make any difference...but you can never be 100% sure!


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-11 Thread Martin Walsh
Tony Cappellini wrote:
> Martin Walsh mwalsh at groktech.org
> Sun Nov 11 06:13:10 CET 2007
> 
>>> That is odd.
> 
>>> Try using the full path to python, just to be sure: c:\python25\python
>>> script.py -- do you get the same behavior?
> This works just fine- I would expect it to.

Actually, I would have expected the opposite. My initial thought based
on your description was that python2.5 is being invoked with PYTHON* env
vars from a previous install, or some site module weirdness. But, the
fact that running python.exe with it's full path corrects the issue,
seems to indicate a problem with your PATH, rather than any python
specific environment setting. What does 'set PATH' report?

Though this still doesn't explain why you get python2.5 interactively,
and python2.3 when running a script -- perhaps I'm still unclear what
you are seeing. Would the following be an accurate description of the
behavior?

assuming:
- you run inside a fresh 'cmd' console each time (typing 'cmd' at the
run dialog, or similar), to be sure there is no app environment kruft

- the current working directory doesn't contain any programs, scripts or
possibly links that could interfere (preferably an empty path)

- you don't have any PYTHON* environment vars set (including PYTHONSTARTUP)

you observe:
- when you type 'python' (only 'python') at the prompt, you get
python2.5 interactively

- when you use the form 'python script.py', the script is run with
python2.3 (can you verify with sys.version?) with sys.path appropriate
for 2.3

- when you use the form 'c:\python25\python.exe script.py', the script
is executed with python2.5 and you have the correct sys.path (for 2.5)

> 
>>> Also, if you haven't already, you can run python with the -E and/or -S
>>> flags (ex. 'c:\python25\python -E -S script.py'). The -E flag will cause
>>> the PYTHONPATH and PYTHONHOME environment variables to be ignored. And
> 
> This also works just fine. I've tried both switches independently, and
> the scrip runs normally when I use either and both at the same time.
> If I don't use them, then Python2.3 is being invoked somehow.

Yeah, very odd indeed.

 > Very strange indeed. It's starting to remind me of an episode from The
> Twilight Zone ;-)
> 
> Is ti possible that my registry is corrupted?

I wouldn't think so, but I suppose it is possible. I believe all the
pertinent registry keys are store under
"HKLM\Software\Python\Pythoncore\", so you could have a look.
There are settings stored elsewhere, but I think they are all related to
file associations, and enabling double-click launching etc. I hope
someone will correct or clarify, if I'm wrong.

If it is a registry issue, re-installing python2.5 *may* provide a quick
fix. BTW, are you using an alternate distribution of python (ex.
ActiveState), or the standard python.org version?

HTH,
Marty
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-11 Thread Tony Cappellini
Martin Walsh mwalsh at groktech.org
Sun Nov 11 06:13:10 CET 2007

>>That is odd.

>>Try using the full path to python, just to be sure: c:\python25\python
>>script.py -- do you get the same behavior?
This works just fine- I would expect it to.

>>Also, if you haven't already, you can run python with the -E and/or -S
>>flags (ex. 'c:\python25\python -E -S script.py'). The -E flag will cause
>>the PYTHONPATH and PYTHONHOME environment variables to be ignored. And

This also works just fine. I've tried both switches independently, and
the scrip runs normally when I use either and both at the same time.
If I don't use them, then Python2.3 is being invoked somehow.

However, when I type set PYTHONPATH and
set PYTHONHOME

at the cmd prompt

SET PYTHONPATH
Environment variable PYTHONPATH not defined

SET PYTHONHOME
Environment variable PYTHONHOME not defined

Very strange indeed. It's starting to remind me of an episode from The
Twilight Zone ;-)

Is ti possible that my registry is corrupted?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-10 Thread Martin Walsh
Tony Cappellini wrote:
>>> What do you get if you print sys.path from
>> the interpreter?
> 
> I've printed out sys.path from inside the script as well,
> and all references to Python25 are replaced with Python23
> 
> 
> FWIW- This isn't a problem unique to this script.
> I've just printed out sys.path from another script in another
> directory, and Python2.3 is referenced.
> So, it's a system wide issue- but I still don't know how or why it's 
> happening.

That is odd.

Try using the full path to python, just to be sure: c:\python25\python
script.py -- do you get the same behavior?

Also, if you haven't already, you can run python with the -E and/or -S
flags (ex. 'c:\python25\python -E -S script.py'). The -E flag will cause
the PYTHONPATH and PYTHONHOME environment variables to be ignored. And
the -S flag prevents 'import site' at python startup. Regardless, even
if these are configured incorrectly I would expect the same behavior if
running a script or using the interactive interpreter.

You mentioned that python 2.4 is installed also... does it have the same
sys.path problem?

HTH,
Marty


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-10 Thread Tony Cappellini
>>What do you get if you print sys.path from
> the interpreter?

I've printed out sys.path from inside the script as well,
and all references to Python25 are replaced with Python23


FWIW- This isn't a problem unique to this script.
I've just printed out sys.path from another script in another
directory, and Python2.3 is referenced.
So, it's a system wide issue- but I still don't know how or why it's happening.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-10 Thread Tony Cappellini
Thanks for replying Kent.
This is quite a strange mystery.

> A couple of possibilities...
> Is there a #! line at the start of the script that specifies Python 2.3
> (I'm not sure if those work in windows though...)
No- The shebang line is for non-Windows systems (Unix variants)

> How do you run the script? If you double-click it, perhaps the file
> association with .py files is to Python 2.3?
I run the script by typing python script.py

> Conceivably the Python 2.5 module path is incorrect and imports the
> wrong module. What happens if you import logging from the interpreter
> prompt and print its file?

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.__file__
'C:\\PYTHON25\\lib\\logging\\__init__.pyc'


What do you get if you print sys.path from
> the interpreter?

>>> import sys
>>> sys.path
['', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\PYTHON25\\DLLs',
'C:\\PYTHON25\\lib', 'C:\\PYTHON25\\lib\\plat-win', 'C
:\\PYTHON25\\lib\\lib-tk', 'C:\\PYTHON25',
'C:\\PYTHON25\\lib\\site-packages',
'C:\\PYTHON25\\lib\\site-packages\\win32'
, 'C:\\PYTHON25\\lib\\site-packages\\win32\\lib',
'C:\\PYTHON25\\lib\\site-packages\\Pythonwin', 'C:\\PYTHON25\\lib\\sit
e-packages\\wx-2.8-msw-ansi']
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-10 Thread Kent Johnson
Tony Cappellini wrote:
> When I run this python script, the following exception is thrown,
> implying that it is being executed with Python 2.3
> So I've added this print statement to the main function, which shows
> the logging module is being imported from the Python 2.3 directory
> 
> print"\nlogging.__file__ = %s" % logging.__file__
> 
> logging.__file__ = C:\Python23\lib\logging\__init__.pyc
> 
> 
> 
> Traceback (most recent call last):
>   File "c:\Project\myscript.py", line 584, in
> ?
> main(sys.argv)
>   File "c:\Project\myscript.py", line 518, in
> main
> logging.basicConfig(level=config.verbosity,format='%(message)s')
> TypeError: basicConfig() takes no arguments (2 given)
> 
> 
> The really odd thing is when I bring up the python interpreter at the
> same command prompt where i ran the script above,
> Python 2.5 is invoked, as seen by
> 
> 
> Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
 import sys
 sys.version
> '2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)]'
> 
> 
> How is it that running a script invokes Python 2.3, but running the
> interpreter without the script invoked Python 2.5?

A couple of possibilities...
Is there a #! line at the start of the script that specifies Python 2.3 
(I'm not sure if those work in windows though...)

How do you run the script? If you double-click it, perhaps the file 
association with .py files is to Python 2.3?

Conceivably the Python 2.5 module path is incorrect and imports the 
wrong module. What happens if you import logging from the interpreter 
prompt and print its file? What do you get if you print sys.path from 
the interpreter?

HTH,
Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Wrong version of Python being executed

2007-11-10 Thread Tony Cappellini
I've got Python 2.3, 2.4 and 2.5 installed on a Windows XP machine..

I currently have Python 2.5 in my path, and there are no other
versions of Python in the path.

I'm trying to run a program which expects Python 2.4 or later to be
installed, because there is a call to logging.BasicConfig(arg1, arg2)
which is passed two arguments

In Python 2.3, logging.BasicConfig() did not take any arguments.

When I run this python script, the following exception is thrown,
implying that it is being executed with Python 2.3
So I've added this print statement to the main function, which shows
the logging module is being imported from the Python 2.3 directory

print"\nlogging.__file__ = %s" % logging.__file__

logging.__file__ = C:\Python23\lib\logging\__init__.pyc



Traceback (most recent call last):
  File "c:\Project\myscript.py", line 584, in
?
main(sys.argv)
  File "c:\Project\myscript.py", line 518, in
main
logging.basicConfig(level=config.verbosity,format='%(message)s')
TypeError: basicConfig() takes no arguments (2 given)


The really odd thing is when I bring up the python interpreter at the
same command prompt where i ran the script above,
Python 2.5 is invoked, as seen by


Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.version
'2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)]'


How is it that running a script invokes Python 2.3, but running the
interpreter without the script invoked Python 2.5?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor