J23
J23

Reputation: 3221

Python 3.x Drag-And-Drop Broken in Windows

Previously, I had Python 3.7.4 installed & working great on Win10. Then, a 3rd party installer (unbeknownst to me) installed Python 2.7...which completely hosed my Python environment (ugh). After removing Python 2.7 and running a repair-reinstall of Python 3.7.4, it's mostly back up and running - except for the ability to drag and drop onto .py files.

Per Drag and drop onto Python script in Windows Explorer and Python Drag-and-drop broken, I've tried:

regedit:

HKCR\.py=Python.File (when I first checked, it was set to py_auto_file, so I did have to change this)
HKCR\Python.File\shell\open\command="C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\python.exe" "%1"
HKCR\Python.File\shellex\DropHandler= I've tried {60254CA5-953B-11CF-8C96-00AA00B8708C}, {86C86720-42A0-1069-A2E8-08002B30309D}, and {BEA218D2-6950-497B-9434-61683EC065FE}

With the above changes, I was able to get Python to launch when dragging-and-dropping onto .py files, but sys.argv does not contain the filename (only argv[0] is set, not argv[1]). Obviously I'm restarting Windows Explorer between each test. I've spent the past several hours searching & reading, but everything I've found pretty much contains some variation of the 3 changes above.

Any ideas why argv[1] would not be set when launching Python by dragging a file onto a .py script?

Upvotes: 2

Views: 1708

Answers (2)

Red
Red

Reputation: 349

Drag and drop did not work here too, because I had accidentally selected a new standard opening program via:

rightclick on a .py file -> open with -> [select any program] -> check the box "use as standard"

in Windows Explorer for .py files.

This killed the drag and drop feature - and also the option "edit with IDLE" is no longer visible in the context menu (this missing entry is a hint for this very user mistake)

Probably you had tried the "use as standard" checkbox as well, to repair your broken python installation.


To get back drag and drop and standard behavior:

A) delete the registry key "openwith" in

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py

B) reinstall python (or repair the installation)


Background

The "openwith" registry key is only created by the explorer once you set a new standard program. This key is overriding any system defaults from the other registry keys in HKLM and HKCU.

Even if you manually set the "openwith" key to your python.exe (via right click, ... ) windows will just alter the command at the "openwith" key to point to the python.exe - but the DropHandler will still not be applied, because the ShellEx Key is missing in this registry "folder".

And no: I have not yet found this solution anywhere. A search for ".py" in the registry pointed towards this registry key and fiddling with it solved the problem in the end.

If anyone from the python installer reads this: maybe offer the option to delete this key during the installation - to recover properly from any mis-setting.

Upvotes: 0

J23
J23

Reputation: 3221

I managed to solve this by:

  • Do a repair-reinstall of Python 3
  • Do a repair-reinstall of Python Launcher
  • Create HKCU\Software\Classes\Python.File\shellex\DropHandler, with default={BEA218D2-6950-497B-9434-61683EC065FE}
  • Modify HKLM\Software\Classes\Python.File\shell\open\command, to set default="C:\Users\my_user_name\AppData\Local\Programs\Python\Python37-32\python.exe" "%1" %*

Upvotes: 0

Related Questions