Proper set-up for a co-existant python 2.6 & 3.1 installation

V

vsoler

I started learning python with ver 2.6. Then I switched to 3.1 after
uninstalling the previous version.

Now I find that many of the code snippets that I would need are
written for py 2.6. Sometimes the automatic converter 2to3 doesn't
help, because it is not able to complete its objective and request
manual "tuning" from the user.

This is to tell you that I would like to have both versions running on
my PC. I am using Windows 7 at home, and Windows Vista in the office.

Right now, the two versions are installed on the PC I have at home. If
I go to the directory C:\python26 or C:\python31 and I type "python",
the correct version of python is launched. I need the pywin32
extensions in either case.

I was about to feel happy that everything worked when I found that I
cannot change the file associations.

If I want to work with py 3.1, I want that a double click on a *.py
file launches python 3.1, and not 2.6.
On the other hand, when I pan to work with py 2.6 I want that a double
click on a*.py file launches python 3.1.

I keep source files (*.py) for either version in different
directories.

I tried to change file associations, first manually, in a CMD window.
But the system was responding "access denied" even when I used an
Administrator account (I was using FTYPE python.file="C:
\Python26\python.exe" "%1" %*).

So I directed my efforts towards the Control Panel. But here I got
lost. I am not able to find the python file associations (I can find
others, but not python's).

Perhaps I am focussing my efforts in the wrong direction, but I am not
aware of any alternative one.

Perhaps you can help me.

Thank you
Vicente Soler
 
M

Martin v. Loewis

I tried to change file associations, first manually, in a CMD window.
But the system was responding "access denied" even when I used an
Administrator account (I was using FTYPE python.file="C:
\Python26\python.exe" "%1" %*).

That works, in principle. Put that command into py26.bat, then, in
Explorer, Run As Administrator. Make sure to double-escape the percent
signs.

Alternatively, you can also write a program that writes to
HKEY_CURRENT_USER; that would take precedence over HKEY_LOCAL_MACHINE.

Regards,
Martin
 
V

vsoler

That works, in principle. Put that command into py26.bat, then, in
Explorer, Run As Administrator. Make sure to double-escape the percent
signs.

Alternatively, you can also write a program that writes to
HKEY_CURRENT_USER; that would take precedence over HKEY_LOCAL_MACHINE.

Regards,
Martin

When I am logged-in in a session as an administrator, the BAT file on
the Desktop, and I double-click on it, it does not work.

However, if instead of double-clicking on the BAT file, I enter the
Explorer and I run the BAT file as administrator, then something seems
to start working. Excellent!

When you say to double-escape the percent signs, do you mean that in
my BAT file I should write...

FTYPE python.file="C:\Python26\python.exe" "%%1" %%*

and the inverted commas around %%*, are they not necessary?

Vicente Soler
 
M

Martin v. Loewis

When I am logged-in in a session as an administrator, the BAT file on
the Desktop, and I double-click on it, it does not work.

This is not what I meant. Instead, right-click on the BAT file,
and select "run as administrator".
When you say to double-escape the percent signs, do you mean that in
my BAT file I should write...

FTYPE python.file="C:\Python26\python.exe" "%%1" %%*

and the inverted commas around %%*, are they not necessary?

No, I don't think so.

Regards,
Martin
 
V

vsoler

This is not what I meant. Instead, right-click on the BAT file,
and select "run as administrator".




No, I don't think so.

Regards,
Martin

Martin (or anybody else),

The problem with FTYPE is solved.

However, after having switched to py 3.1 with the help of the BAT
script (which only changes FTYPE) I have another problem.

(Just for reference, here is my batch file)

@ECHO OFF
ECHO ************************************************
ECHO Cambia a Python 3.1
ECHO ************************************************
ECHO *
ECHO FTYPES:
ECHO *
ECHO .py=Python.File
ECHO .pyc=Python.CompiledFile
ECHO .pyo=Python.CompiledFile
ECHO .pys=pysFile
ECHO .pyw=Python.NoConFile
ECHO *
ECHO ************************************************
ECHO *
FTYPE python.file="C:\Python31\python.exe" "%%1" %%*
FTYPE python.compiledfile="C:\Python31\python.exe" "%%1" %%*
FTYPE python.NoConFile="C:\Python31\pythonw.exe" "%%1" %%*
ECHO *
Pause
@ECHO ON

The problem is that, if I am on top of a .py file, and, with the
mouse, I click on the right button, then I click on "Edit with IDLE",
I get the 2.6 system, not the 3.1 one (which was supposed to be the
correct one after the change).

My question is: are there any other changes that I should do in order
to fully switch from one version to another?

Thank you in advance.

Vicente Soler
 
M

MRAB

Martin said:
This is not what I meant. Instead, right-click on the BAT file,
and select "run as administrator".


No, I don't think so.
%1 is the placeholder for parameter 1, which you do want quoted.

%* is the placeholder for all the remaining parameters, which you don't
want quoted as single string.
 
M

Mark Tolonen

vsoler said:
Martin (or anybody else),

The problem with FTYPE is solved.

However, after having switched to py 3.1 with the help of the BAT
script (which only changes FTYPE) I have another problem.

(Just for reference, here is my batch file)

@ECHO OFF
ECHO ************************************************
ECHO Cambia a Python 3.1
ECHO ************************************************
ECHO *
ECHO FTYPES:
ECHO *
ECHO .py=Python.File
ECHO .pyc=Python.CompiledFile
ECHO .pyo=Python.CompiledFile
ECHO .pys=pysFile
ECHO .pyw=Python.NoConFile
ECHO *
ECHO ************************************************
ECHO *
FTYPE python.file="C:\Python31\python.exe" "%%1" %%*
FTYPE python.compiledfile="C:\Python31\python.exe" "%%1" %%*
FTYPE python.NoConFile="C:\Python31\pythonw.exe" "%%1" %%*
ECHO *
Pause
@ECHO ON

The problem is that, if I am on top of a .py file, and, with the
mouse, I click on the right button, then I click on "Edit with IDLE",
I get the 2.6 system, not the 3.1 one (which was supposed to be the
correct one after the change).

My question is: are there any other changes that I should do in order
to fully switch from one version to another?

Yes, and they are relatively easy to edit with a .reg file instead of a
batch file. Below is just an example for type "Python.File" that adds "Open
with Python3", "Edit with IDLE3", and "Open with Pythonwin3" commands to the
right-click context menu of a .py file. The first 3 entries are the
original Python26 entries. The last three were copied from them and
modified to create the alternative context menus. You could also create two
..reg files that toggle the original three entries between Python 2.6 and
Python 3.1 if you want.

-----------------------START------------------------

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE\command]
@="\"C:\\Python26\\pythonw.exe\"
\"C:\\Python26\\Lib\\idlelib\\idle.pyw\" -n -e \"%1\""

[HKEY_CLASSES_ROOT\Python.File\shell\Edit with Pythonwin\command]
@="C:\\Python26\\Lib\\site-packages\\Pythonwin\\Pythonwin.exe /edit \"%1\""

[HKEY_CLASSES_ROOT\Python.File\shell\open\command]
@="\"C:\\Python26\\python.exe\" \"%1\" %*"

[HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE3\command]
@="\"C:\\Python31\\pythonw.exe\"
\"C:\\Python31\\Lib\\idlelib\\idle.pyw\" -n -e \"%1\""

[HKEY_CLASSES_ROOT\Python.File\shell\Edit with Pythonwin3\command]
@="C:\\Python31\\Lib\\site-packages\\Pythonwin\\Pythonwin.exe /edit \"%1\""

[HKEY_CLASSES_ROOT\Python.File\shell\Open with Python3\command]
@="\"C:\\Python31\\python.exe\" \"%1\" %*"

-------------------END---------------------------

-Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top