Confluence Retirement

In an effort to consolidate USGS hosted Wikis, myUSGS’ Confluence service is scheduled for retirement on January 27th, 2023. The official USGS Wiki and collaboration space is now SharePoint. Please migrate existing spaces and content to the SharePoint platform and remove it from Confluence at your earliest convenience. If you need any additional information or have any concerns about this change, please contact myusgs@usgs.gov. Thank you for your prompt attention to this matter.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The following workflow will demonstrate how to install the Pandas module for python as an example. Pandas is great for a whole variety of data processing tasks (just google "python pandas"). It is not a standalone module; it sits on top of numpy. A version of Pandas only works with a specific version of numpy. Since we don't want to mess with the version of numpy that comes with ESRI software, we need to match the version of Pandas that will be happy with the ESRI version of numpy. Generally, the ESRI numpy and the rest of the python environment is going to be older than what you might be able to pull from the internet, so you need to figure out which of the older versions of the module (Pandas, in this case) is a fit

The following example is for ArcGIS 10.2.2.

In this example, ArcGIS 10.2.0 2 is featured. This means that numpy version 1.67.1 is installed. This can be checked for your ArcMap Python window by typing:

A. Find the versions of numpy and matplotlib Arc is using.

Open ArcMap and its Python window, and enter these commands:

>>> import sys, numpy, matplotlib
>>> print(sys.version, numpy.__version__

...

Here is a table of numpy versions associated with different ArcGIS versions (link).

As mentioned above, the installed version of Pandas must work with the ESRI numpy. It's a minor hassle to figure this out because there's no handy table (that I could find) listing this dependency for different Pandas versions. My totally inefficient strategy is to:

go to the Pandas web site

select the doc for a randomly selected version of Pandas (say, 0.10.0 for our example)

search that page for the word "depend" and follow the link

the dependency page will state the version of numpy needed (1.6.1 in our example version of ArcGIS 10.2.0)

...

, matplotlib.__version__)
'2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)]', '1.7.1', '1.3.0')

B. Create an Anaconda virtual environment (including pandas) that is compatible with ArcGIS 10.2.2.

 Rather than modifying the basic Anaconda installation, you can create a custom environment within Anaconda and specify the version of Pandas you want there. To do this:

  1. Get to the Anaconda Command Prompt (via the Start menu on Windows, e.g.Start > Search > Anaconda, pick "Anaconda Command Prompt")
  2. Type "conda create -n esri arc1022 python=2.7.3 numpy5 numpy=1.7.1 matplotlib=1.63.0 xlrd=0.9.2 pandas xlwt=0.10.0"

...

  1. .7.5 pyparsing=1.5  pandas"
  2. Anaconda's conda command will then:
  • Determine that the specified versions are compatible
  • Find most recent compatible versions of packages not completely specified 
  • Prompts you to continue
  • Downloads (only) the pieces you need to "overlay" with the base environment to get the environment you have specified.
  • Set up a subdirectory in the Anaconda install folder "arc1022" and downloads these packages into it.

C. Test the virtual environment

D:\Users\cprice>activate arc1022
Activating environment "arc1022"...
[arc1022] D:\Users\cprice>conda list
# packages in environment at D:\Users\cprice\Anaconda\envs\arc1022:
#
D:\Users\cprice\Anaconda\envs\arc1022\lib\site-packages\pip\_vendor\requests\pac
ng: A true SSLContext object is not available. This prevents urllib3 from config
nnections to fail. For more information, see https://urllib3.readthedocs.org/en/
InsecurePlatformWarning
dateutil 2.4.1 py27_0
numpy 1.7.1 py27_3
pandas 0.13.0 np17py27_0
pip 7.0.3 py27_0
pyparsing 1.5.6 py27_0
python 2.7.5 2
python-dateutil 2.4.1 <pip>
pytz 2015.4 py27_0
setuptools 17.1.1 py27_0
six 1.9.0 py27_0
xlrd 0.9.2 py27_0
xlwt 0.7.5 py27_0
[arc1022] D:\Users\cprice>python
Python 2.7.5 |Continuum Analytics, Inc.| (default, Jul 1 2013, 12:41:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

E. Add arcpy to the environment's Python path

[arc1022] D:\Users\cprice>copy c:\Python27\ArcGIS10.2\lib\site-packages\desktop10.2.pth d:\Users\cprice\Anaconda\envs\arc1022\lib\site-packages

F: Test to make sure things are working

[arc1022] D:\Users\cprice>python
Python 2.7.5 |Continuum Analytics, Inc.| (default, Jul 1 2013, 12:41:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import arcpy
>>> import pandas
>>> 

 

2) Configure ArcGIS

At this point, Anaconda has two versions of Pandas installed. The too-new default and the one you installed within the "esri" environment that should work with ArcGIS. ArcGIS, at this point, still has no way to understand that either version exists.  We hope to improve on the tactic described here in the near future but for now you will add a small ASCII file to a directory in the ESRI Python directories. This file, which specifies the path to the Anaconda "esri" environment, will be read whenever the ESRI Python interpreter is instantiated. This will enable ESRI python to find Pandas.

...