[Tutor] Wrong version of Python being executed

Tony Cappellini cappy2112 at gmail.com
Mon Nov 19 21:16:28 CET 2007


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 <kent37 at tds.net> 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
>


More information about the Tutor mailing list