General questions about Python scripting in ArcGIS and Python add-in development

405
4
Jump to solution
12-19-2013 07:59 AM
DongxiZheng
New Contributor III
Howdy,

I am a totally newbie to everything in ArcGIS related to Python, although I am familiar with Python on its own. I tried to search through the ArcGIS documentation for answers to the following basic questions but got overwhelmed and lost in the massive information. So if someone can give me direct answers or point me to specific references (not general please), I will very appreciate it.

Questions:

  1. Does ArcMap 10.2 come with Python? i.e., if I don't install Python manually, will Python scripting work in ArcGIS?

  2. If the answer to the above question is yes, then ArcMap must have installed a copy of Python somewhere to be invoked. Where is this copy of Python used by ArcMap? Can I change it so ArcMap invoke another copy of Python that I installed manually?

  3. Similar to the first question, will a Python Add-in work if Python is not installed manually?

  4. What could possibly be the reason if ArcMap shows a command as missing in a toolbar from a Python Add-in?

P.S., please consider all the above questions on a Windows 7 64-bit system.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
PhilMorefield
Occasional Contributor III

  1. Yes. Yes.

  2. Yes. The default installation is usually: C:\Python27\ArcGIS10.2\... Yes, it is possible to have multiple installations of Python on your computer (intentionally or not). But only one can be the default installation recognized by Windows. If you want to use your own Python installation, I recommend doing that installation first, then installing ArcGIS  (you'll be given the option to install Python or not). I don't personally recommend having multiple Python installations lying around unless you need them and know what you're doing.

  3. Yes. As long as you've installed Python 2.7.x and numpy, everything should work.

  4. This is a potentially very different and unrelated problem. You'll have to provide more specifics.

Some information about Python installations and ArcGIS can be found at the bottom of this page.

View solution in original post

0 Kudos
4 Replies
PhilMorefield
Occasional Contributor III

  1. Yes. Yes.

  2. Yes. The default installation is usually: C:\Python27\ArcGIS10.2\... Yes, it is possible to have multiple installations of Python on your computer (intentionally or not). But only one can be the default installation recognized by Windows. If you want to use your own Python installation, I recommend doing that installation first, then installing ArcGIS  (you'll be given the option to install Python or not). I don't personally recommend having multiple Python installations lying around unless you need them and know what you're doing.

  3. Yes. As long as you've installed Python 2.7.x and numpy, everything should work.

  4. This is a potentially very different and unrelated problem. You'll have to provide more specifics.

Some information about Python installations and ArcGIS can be found at the bottom of this page.
0 Kudos
DongxiZheng
New Contributor III

  1. Yes. Yes.

  2. Yes. The default installation is usually: C:\Python27\ArcGIS10.2\... Yes, it is possible to have multiple installations of Python on your computer (intentionally or not). But only one can be the default installation recognized by Windows. If you want to use your own Python installation, I recommend doing that installation first, then installing ArcGIS  (you'll be given the option to install Python or not). I don't personally recommend having multiple Python installations lying around unless you need them and know what you're doing.

  3. Yes. As long as you've installed Python 2.7.x and numpy, everything should work.

  4. This is a potentially very different and unrelated problem. You'll have to provide more specifics.

Some information about Python installations and ArcGIS can be found at the bottom of this page.


Thanks a lot philmorefield!
Some follow-ups:

  1. Regarding the last question I asked: No worry about that. I figured out later that it was caused by my screwing up the Python27 folder and related registry with temptations of uninstallation and reinstallation. To fix that, I cleared up all copies of Python on my computer, installed a brand new Python2.7 (in D:\Program Files\Python27), and repaired ArcGIS from CD (with "its" Python installed in D:\Program Files\Python27\ArcGIS10.2 and registered). Everything worked fine in ArcGIS after doing these.

  2. Kind of following the above bullet and regarding your instruction on redirecting ArcGIS to use my installation of Python: So the fact is both copies exist and one nests in the other's folder. As suggested by you and most python users, maintaining only one copy of python is preferred. I prefer to keep my installation of Python since I have other non-ArcGIS related python projects using this copy. In this case, what should I do to let ArcGIS refer to my copy instead of its own copy and get rid of its own copy? I noticed that ArcGIS' copy contains more site-packages and its own configuration files (e.g., desktop10.2.pth). When redirecting, should I copy all these additional items over?

0 Kudos
PhilMorefield
Occasional Contributor III
Thanks a lot philmorefield!
Some follow-ups:

  1. Regarding the last question I asked: No worry about that. I figured out later that it was caused by my screwing up the Python27 folder and related registry with temptations of uninstallation and reinstallation. To fix that, I cleared up all copies of Python on my computer, installed a brand new Python2.7 (in D:\Program Files\Python27), and repaired ArcGIS from CD (with "its" Python installed in D:\Program Files\Python27\ArcGIS10.2 and registered). Everything worked fine in ArcGIS after doing these.

  2. Kind of following the above bullet and regarding your instruction on redirecting ArcGIS to use my installation of Python: So the fact is both copies exist and one nests in the other's folder. As suggested by you and most python users, maintaining only one copy of python is preferred. I prefer to keep my installation of Python since I have other non-ArcGIS related python projects using this copy. In this case, what should I do to let ArcGIS refer to my copy instead of its own copy and get rid of its own copy? I noticed that ArcGIS' copy contains more site-packages and its own configuration files (e.g., desktop10.2.pth). When redirecting, should I copy all these additional items over?


Do these steps in order and you should be okay:

  1. Copy the Desktop10.2.pth file and move it to the Python installation you want to keep: D:\Program Files\Python27\Lib\site-packages

  2. Delete the entire Python installation you don't want to keep. Just hit the delete key and remove the whole folder: D:\Program Files\Python27\ArcGIS10.2

  3. Go into System Properties->Advanced->Environment Variables and take a look at the "Path" System Variable. There should be only two reference to any Python folder there: D:\Program Files\Python27 and D:\Program Files\Python27\Scripts. If those aren't there, add them. If any other Python-related path is there, delete it.

  4. Check to see if you have numpy 1.6.x and matplotlib 1.1.x installed. If not, install them. If you want to match the ArcGIS installation you could add xlrd and xlwt as well.


For future reference, running the ArcGIS installer will give you an option to skip the Python installation. You do this by selecting a "Custom" installation and then un-selecting Python.
0 Kudos
DongxiZheng
New Contributor III
Do these steps in order and you should be okay:

  1. Copy the Desktop10.2.pth file and move it to the Python installation you want to keep: D:\Program Files\Python27\Lib\site-packages

  2. Delete the entire Python installation you don't want to keep. Just hit the delete key and remove the whole folder: D:\Program Files\Python27\ArcGIS10.2

  3. Go into System Properties->Advanced->Environment Variables and take a look at the "Path" System Variable. There should be only two reference to any Python folder there: D:\Program Files\Python27 and D:\Program Files\Python27\Scripts. If those aren't there, add them. If any other Python-related path is there, delete it.

  4. Check to see if you have numpy 1.6.x and matplotlib 1.1.x installed. If not, install them. If you want to match the ArcGIS installation you could add xlrd and xlwt as well.


For future reference, running the ArcGIS installer will give you an option to skip the Python installation. You do this by selecting a "Custom" installation and then un-selecting Python.


Thanks a lot Phil!
0 Kudos