Tuesday 21 February 2017

arcpy - Making Python Add-Ins for ArcMap after installing ArcGIS Pro prevents double-click running of makeaddin.py at Python 2.x?


I've been working quite a lot with Python Add-Ins over the past week or so in a Windows 7 SP1 configuration with ArcGIS 10.3.1 for Desktop and ArcGIS Pro 1.0.2 installed. I also installed Python 3.4.1 that comes with ArcGIS Pro and two versions of Python were happily co-existing.


Every time I made changes to my Python script in the Install subfolder and then returned to the Python Add-In folder and double-clicked makeaddin.py I would see that my *.esriaddin file had been updated because its Date Modified changed in Windows Explorer.


Then I upgraded ArcGIS Pro to version 1.1 this morning, and the double-clicking of makeaddin.py ceased to update my *.esriaddin file. I also noticed that right-clicking on a *.py and choosing Edit with IDLE now opened it with Python 3.4.1 (from ArcGIS Pro 1.1) instead of 2.7.8 (from ArcGIS 10.3.1 for Desktop). I was able to get Edit with IDLE working the way I wanted it to by referring to Distinguishing Python version when using IDLE with ArcGIS Pro and ArcGIS 10.x for Desktop architecture?



However, double-clicking makeaddin.py still does not update my *.esriaddin file, so I know that something is astray with its file association. As a workaround I am able to right-click on makeaddin.py, Edit with IDLE (which is using Python 2.7.8) and use F5 (Run | Run Module) to run it. However, I am keen to get the double-click working again.


Does anyone have a sure-fire method to check and reset the ArcGIS installed version of Python that is run by double-clicking a *.py file?


That ArcGIS Pro installation changes Windows file associations for *.py files is documented but how to change them back is not:



Windows uses file associations to associate a file extension with an executable. When executing a file, the last installation that modifies that file association wins, so if there are multiple versions of Python, the last version installed will be the one used when a .py file is double-clicked or called from a command prompt. Additionally, if a version of Python is uninstalled, the file associations for a .py will be removed.




Answer



I've figured this out with help from some nudging comments by @ChrisW on this question and an old answer by @MattWilkie.


Please only do the following at your own risk because I profess no system administration skills.




  1. I opened a CMD window from the Windows Start Menu as Administrator


  2. I checked the current file association for *.py files by typing:


    assoc .py=




which returned:



.py=Python.File






  1. I checked the current file type by typing:


    ftype Python.File




which returned:



Python.File="C:\Python34\python.exe" "%1" %*






  1. I changed the file type by typing:


    ftype Python.File="C:\Python27\ArcGIS10.3\python.exe" "%1" %*




Then without doing anything else, I tried clicking on my makeaddin.py file again and it updated the *.esriaddin correctly.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...