简体   繁体   中英

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?

Given it's windows, have you tried restarting?

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" %*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM