3

I recently installed pywin (I had to change a registry entry to do it, but I changed it back). I also uninstalled Python 2.7, and since then, I can no longer drag and drop files onto my python scripts. I also lost my file associations.

I have since uninstalled, reinstalled, run CCleaner on my registry, I've tried setting the default program to C:\Python3\Python.exe, C:\Python\Pythonw.exe, C:\Windows\py.exe, C:\Windows\pyw.exe, I've restarted my computer, but dragging files onto my script still doesn't work.

I've gone through a ton of StackOverflow questions, most of them are from almost 10 years ago and don't seem to be relevant anymore. Does anyone have any ideas? Thanks.

I also tried this but it didn't help

qubodup
  • 8,687
  • 5
  • 37
  • 45
Jonathan Wilson
  • 626
  • 6
  • 14
  • 1
    At its simplest you can try to repair your Python 3 installation to let the installer reset the file association. – Eryk Sun Mar 16 '17 at 10:46
  • 1
    Note that your attempt to manually associate with the executable is something you should not do for scripts that need to accept command-line arguments and implement a drop handler. The file type needs to be associated with a program identifier (ProgId) that has an "open" command template (e.g. `py.exe "%1" %*`) and also the CLSID of a "DropHandler" (e.g. the handler implemented by pyshellext.amd64.dll). Python's installer creates the `Python.File` ProgId for handling .py scripts. – Eryk Sun Mar 16 '17 at 10:50
  • I also tried repairing, it didn't work. I'll try messing around with the open key in the registry. Thanks. edit: it didn't work – Jonathan Wilson Mar 16 '17 at 18:51
  • 1
    Repairing was to fix `Python.File` to have the right template, icon, and drop handler, in case that was the problem. The next step is to use the control panel "Default Programs" dialog to change the .py file association. The app to use should be named "Python", and if you elected to install the py launcher, the icon should have a rocket on it. – Eryk Sun Mar 16 '17 at 23:39
  • Thanks, I finally figured it out. My registry keys were broken for some reason and I had to manually fix it – Jonathan Wilson Mar 18 '17 at 01:28

1 Answers1

2

I poked around in the registry and fixed it by doing the following things (not sure which were necessary and which weren't)

First, go to HKEY_CLASSES_ROOT\.py and make sure the value is set to Python.File

Then go to HKEY_CLASSES_ROOT\Python.File\Shell\Open and create a key called "Command" with

"C:\Windows\py.exe" "%1" %* 

as its value. I did the same to CLASSES_ROOT\Applications\py.exe\open\command

Then go to CLASSES_ROOT\Python.File\ShellEx and create a key called "DropHandler" with

{86C86720-42A0-1069-A2E8-08002B30309D}

as its value. that value is the CLSID of a DLL that gets the filename of the file you're dragging and runs it in command, I think?

qubodup
  • 8,687
  • 5
  • 37
  • 45
Jonathan Wilson
  • 626
  • 6
  • 14
  • 1
    `Python.File` should have been repaired by the installer, but maybe you had conflicting settings in your current-user software classes. `HKCR` isn't a real registry hive. It's just a view that merges `HKCU\Software\Classes` and `HKLM\Software\Classes`. It's meant for *reading*, giving priority to the current user's registry hive. You should always modify the real keys when editing the registry; otherwise you can't know if the key you opened was in `HKCU` or `HKLM`, depending on what already exists in the registry. – Eryk Sun Mar 18 '17 at 02:04
  • 4
    Also, if you're running 3.5+ you've set the wrong drop handler. `{86C86720-42A0-1069-A2E8-08002B30309D}` is the standard EXE drop handler that we used to use. It has problems with Unicode filepaths, so Steve Dower created a shell extension library for Windows Python, pyshellext.amd64.dll, that implements a new drop handler with the ID `{BEA218D2-6950-497B-9434-61683EC065FE}`. – Eryk Sun Mar 18 '17 at 02:11