0

i tried in Control Panel\Programs\Default Programs\Set Associations, and also assoc/ftype, but windows keeps using the wrong python.exe (C:\Python27\) instead of the one i want (C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\python-2.7.9.amd64\)

>where python
C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\python-2.7.9.amd64\python.exe
C:\Python27\python.exe
C:\Program Files (x86)\LilyPond\usr\bin\python.exe

>assoc .py
.py=Python.File.WinPython

>ftype Python.File.WinPython
Python.File.WinPython=C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\python-2.7
.9.amd64\python.exe "%1" %*

>set PATH
Path=C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\python-2.7.9.amd64;...C:\Python27;C:\Python27\Scripts;...C:\Program Files (x86)\LilyPond\usr\bin;...
PATHEXT=.PY;...

i just made up Python.File.WinPython, is that allowed?

user1441998
  • 459
  • 4
  • 14
  • Do you need to perform that for all Python scripts in your system or only with particular ones? – myaut Jun 02 '15 at 09:14
  • i'm ok doing it for all, but would rather it could be different for different .py files :) – user1441998 Jun 02 '15 at 09:16
  • You can use `ftype` command to associate the interpreter you want. See my answer to [_Temporary file association for single cmd.exe session_](http://stackoverflow.com/questions/5583024/temporary-file-association-for-single-cmd-exe-session). – martineau Jun 02 '15 at 09:35
  • How are you running your python programs? Are you running (for example) `filename.py` or `python filename.py`? %Path% is read late in the search algorithm, after the system directories. It is a "feature" of Windows that there can only be one association at a time, personally I cope with different python versions by having a `.bat` file for each version. – cdarke Jun 02 '15 at 09:36
  • searching the registry, i find in HKCR: `Applications\python.exe\shell\open\command` and `Local Settings\Software\Microsoft\Windows\Shell\MuiCache` and `py_auto_file\shell\open\command` and `Python\shell\open\command` and `Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache` and `HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py\OpenWithList` and similar in `HKLM` and `HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Python.exe` that all mention the other python.exe's, are they causing this? – user1441998 Jun 02 '15 at 10:07
  • @cdarke - `python filename.py` works fine, i want just `filename`. do you know about pylauncher? other SO answers mention it solves this problem, and apparently included in python3 now. @martineau, OP shows ftype is set -- why isn't it working? – user1441998 Jun 02 '15 at 10:15
  • 1
    `assoc` and `ftype` set the system associations that are stored in `HKLM\Software\Classes`. Per-user settings, created by Explorer, override system settings. Check in `HKCU\Software\Classes` and `HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts`. There are other places where this can be configured (it's a hideously bad design). If you have the system file association configured properly, I recommend deleting all of the per-user settings. It's easier to manage just the system settings using `assoc` and `ftype`. – Eryk Sun Jun 02 '15 at 14:13
  • 2
    If you install Python 3, that sets up the file associations to use py.exe and pyw.exe. With the new launcher you can run any installed version from the command line (e.g. `py -2.7 filename.py`), or associate a script with a particular installed version by adding a shebang line. – Eryk Sun Jun 02 '15 at 14:18

1 Answers1

0

https://github.com/winpython/winpython/wiki/Installation#Registration

(but you will loose your python2.7 registration if you do that)

the other solution is :

call C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\scripts\env.bat
python my_progam_.py
stonebig
  • 1,193
  • 1
  • 9
  • 13