USGS EGIS web pages
EGIS Home
EGIS Support
Metadata
Training
Email Lists
Esri Events
External web pages
Esri Support
Esri Product Help
Esri GeoNet
GIS Stack Exchange
EGIS wiki space (here)
Table of Contents | ||||
---|---|---|---|---|
|
Warning | ||||
---|---|---|---|---|
| ||||
The steps below are for a non-administrative install. If you want to install and maintain Anaconda for all users, please go to this version of the instructions. (Admin access required) |
Anaconda is an open-source Python distribution that makes is possible to easily install and manage many pre-packaged third party Python modules. It is a competing fully open-source alternative to the Enthought Python Distribution (EPD).It has some big advantages
It has some big advantages over using the Python Esri provides with ArcGIS:
...
...
The general workflow to make this happen is to:
...
Miniconda only includes the minimal Python (the main distribution now includes R and many other packages and is very large).
Download MiniConda for Python 2.7
Download links: ( x32 | x64 ) (save do not run link)
The 32-bit version works with ArcGIS Desktop (which is 32-bit)
The 64-bit version is optional, but required to use Anaconda with ArcGIS background processing (and Pro)
Run the .exe installers
Select install for a single user (Not "All Users")
Set up the console shortcuts
Go to each of your anaconda folders and set up Start menu shortcuts for Anaconda
Code Block | ||||
---|---|---|---|---|
| ||||
cd D:\Users\cprice\Anaconda32\Scripts
conda install console_shortcut
cd D:\Users\cprice\Anaconda64\Scripts
conda install console_shortcut |
actiAt this point, you will have a nice Anaconda setup that's spiffy and new and totally useless with ArcMap.
The following workflow will demonstrate how set up a custom Python environment within Anaconda that is similar to that of ArcGIS Python, and then add a compatible version pandas module. Pandas is great for a whole variety of data processing tasks (just google "python pandas"). If you get this far, you can adapt this workflow to include any other modules you may want.
The following example is for ArcGIS 10.2.2.
The critical modules for compatibility can be found your version of ArcGIS from a command line:
Code Block | ||
---|---|---|
| ||
C:\Users\jwpowell> C:\Python27\ArcGIS10.2\python.exe -c ^
"import sys, numpy, matplotlib;print(sys.version, numpy.__version__, 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 environment for use with ArcGIS
We'll also include a few other modules that we know are shipped in the ArcGIS Python stack.
Since this new custom environment is not the Anaconda default, you need to let it know that's what you want to use. Then, you'll ask it to tell you what's installed.
Open an Anaconda command window and load the virtual environment
...
language | text |
---|
...
The main Anaconda distribution is pretty large (> 3 GB). MiniConda is a smaller version that just includes the Python standard library to start.
You can download and install either one, depending on whether you want to spend the time and disk space. Miniconda most efficient, as you can always download down anything in the conda distibution you want later.
Select install for a single user (Not "All Users")
Anaconda first run
Open the Anaconda prompt window (Search in Windows and start the shortcut "Anaconda Prompt") and enter "python" in the command window:
Code Block | ||||
---|---|---|---|---|
| ||||
(D:\Users\jwpowell\Miniconda2) C:\Users\jwpowell>python
Python 2.7.13 |Continuum Analytics, Inc.| (default, May 11 2017, 14:07:41) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> |
At this point, you have a nice Anaconda Python setup (~ 225 MB) that's spiffy and new and totally useless with ArcMap.
The Department of Interior is now requiring SSL encryption. This means you cannot download Anaconda packages without an SSL certificate in place.
Code Block | ||||
---|---|---|---|---|
| ||||
mkdir %USERPROFILE%\.certificates
copy %USERPROFILE%\Downloads\DOIRootCA2.cer %USERPROFILE%\.certificates
conda config --set ssl_verify %USERPROFILE%\.certificates\DOIRootCA2.cer |
If you plan to use the pip utility to download and install packages not included in the Conda distribution, set up a certificate for pip:
Code Block | ||||
---|---|---|---|---|
| ||||
mkdir %APPDATA%\pip
(echo [global] & echo cert=%USERPROFILE%\.certificates\DOIRootCA2.cer) > %APPDATA%\pip\pip.ini |
The following workflow will demonstrate how set up a custom Python environment within Anaconda that has the same modules installed as ArcGIS Python, and then add a compatible version of Spyder and Jupyter.
The following example is for ArcGIS 10.4.1, assuming you have successfully installed MiniConda 2 32-bit (as above).
The critical modules for ArcGIS compatibility can be determined from your Desktop or Pro Python command line.
(Or you can just look at the list below under B.)
Code Block | ||||
---|---|---|---|---|
| ||||
# pyversions.py - report ArcGIS Python modue versions
# Example output:
# C:\ArcGIS\Pro\bin\ArcGISPro.exe
# Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)]
# matplotlib 1.5.3
# numpy 1.11.2
# scipy 0.18.1
import sys
import os
ff = "{} {}"
try:
print(sys.executable)
print(ff.format("Python", sys.version))
import matplotlib
print(ff.format("matplotlib", matplotlib.__version__))
import numpy
print(ff.format("numpy", numpy.__version__))
import scipy
print(ff.format("scipy", scipy.__version__))
except:
pass |
We'll also include a few other modules that we know are shipped in the ArcGIS Python stack.
Windows 10 won’t show a start menu item if the name of an item/shortcut within the new group matches a shortcut name in another group and has the same target (e.g. both ‘Anaconda2 (32-bit)’ and ‘Anaconda2 (64-bit)’ have a shortcut named ‘Anaconda Prompt’ with a target of cmd.exe which confuses Windows 10). So, when Miniconda2 32-bit (and/or 64-bit) is installed edit the ‘Properties’ of ‘Anaconda Prompt’ -> General tab -> rename to ‘Anaconda Prompt 32-bit’. Also, rename each shortcut that is created for environments for 32-bit or 64-bit similarly for consistency. For example, if you created a new virtual environment in Anaconda 32-bit named arc1041 then you would rename the shortcut from ‘Anaconda Prompt (arc1041)’ to ‘Anaconda Prompt 32-bit (arc1041).
Open an Anaconda command window and load the virtual environment.
Code Block | ||||
---|---|---|---|---|
| ||||
C:\Users\jwpowell> conda info --envs # conda environments: # arc1041 py27_0 pysideD:\Users\jwpowell\Miniconda2\envs\arc1041 root 1.2.1 py27_0 python* D:\Users\jwpowell\Miniconda2 D:\Users\jwpowell>activate arc1041 Activating environment "arc1041"... [arc1022] D:\Users\jwpowell> conda list # packages in environment at D:\Users\jwpowell\Miniconda2\envs\arc1041: # dateutil 2.74.51 2 python-dateutilpy27_0 matplotlib 2.4.1 1.3.0 <pip>np17py27_0 pytznumpy 2016.41.7.1 py27_0 setuptools 21.2.1 py27_0 six 1.10.0 py27_0 wheel 0.29.0 py27_0 xlrd 0.9.4 py27_0 xlwt 1.0.0 py27_0 |
You can add more packages using conda install, but make sure you specify version numbers for these that won't change the environment's version of python or numpy (or ArcGIS will not be able to use that environment anymore).
Let's add the pandas module.
Specifying python, numpy, and matplotlib versions makes sure the environment will still work with ArcGIS, and Anaconda determines the most recent compatible version of pandas (in our case, 0.13.0).
Code Block | ||
---|---|---|
| ||
conda install -n arc1022 python=2.7.5 matplotlib=1.3.0 numpy=1.7.1 pandas
...
The following NEW packages will be INSTALLED:
pandas: 0.13.0-np17py27_0 ### this version works with python 2.7 and numpy 1.7
... |
A few of the most popular things to add to your environment is interactive python ("ipython"), in several flavors:
Code Block | ||
---|---|---|
| ||
conda install -n arc1022 python=2.7.5 matplotlib=1.3.0 numpy=1.7.1 ipython ipython-notebook ipython-qtconsole |
Here is another example, that installs both pandas and spyder, which includes a whole host of tools (including iPython and iPython notebook).
Code Block | ||
---|---|---|
| ||
conda install -n arc1022 python=2.7.5 matplotlib=1.3.0 numpy=1.7.1 pandas spyder |
You can search for more packages available in conda with conda search.
You're not limited to adding only packages to which conda has access to your new environment. Here's an example on how to install a commonly desired GIS-related package (shapely) into a conda virtual environment using the python pip utility:
http://deparkes.co.uk/2015/01/29/install-shapely-on-anaconda/
This can most easily be done (personal opinion) with a Python startup script
python -m site --user-site
C:\Users\username\AppData\Roaming\Python\Python27\site-packages
If you get an error message when you try to import, a common cause is version incompatibilities between Esri's python environment modules and the conda modules. (Condo takes care of compatibility across its environment, but it can't know about versions Esri uses in their python install.) In the pandas example, version 0.10.1 also appears to use the same 1.6.1 version of numpy used by ArcGIS 10.1.x, but some errors occur when trying to import pandas due to some other incompatibility. The solution was to modify the Anaconda environment to use an older version of pandas (0.10.0). The other critical packages are included to avoid having Anaconda install some other incompatible packages.
conda install -n arc101 python=2.7.5 matplotlib=1.3.0 numpy=1.6.1
pandas=0.10.0
http://www.continuum.io/blog/conda
How to do a separate Python installation with ArcGIS? (GIS Stack Exchange)
...
3
... |
You can add more packages using conda install, but make sure you specify version numbers for these that won't change the Python modules required to stay compatible with ArcGIS's Python stack.
Let's add the Jupyter notebook and the Spyder IDE which are both popular additions to your toolbox.
Specifying the list of module versions (ARCLIST) here ensures the environment will still work with ArcGIS 10.4.1.
Code Block | ||||
---|---|---|---|---|
| ||||
set ARCLIST=python=2.7.10 numpy=1.9.2 matplotlib=1.4.3 scipy=0.16.0 pandas pyparsing xlrd xlwt
conda install -n arc1041 %ARCLIST% jupyter spyder
...
The following NEW packages will be INSTALLED:
... |
Conda does provide a method for pinning dependencies to an environment so you don't have to specify them each time (as: ARCLIST above). You need to list these packages in a filed called pinned in the conda-meta folder.
Code Block | ||||
---|---|---|---|---|
| ||||
C:\Users\jwpowell> activate arc1041
(arc1041) C:\Users\jwpowell>(echo python ==2.7.10 & echo numpy ==1.9.2 & echo matplotlib ==1.4.3 & echo scipy ==0.16.0) > %CONDA_PREFIX%\conda-meta\pinned
(arc1041) C:\Users\jwpowell>type %CONDA_PREFIX%\conda-meta\pinned
python ==2.7.10
numpy ==1.9.2
matplotlib ==1.4.3
scipy ==0.16.0 |
Now that this has been set up, conda install -n arc1041 scipy-0.18.1 will generate an error, and conda install six will update six to the highest version compatible with the pinned modules.
You can search for more packages available in conda with conda search. There's a nice list on the Anaconda website that describes them all.
You're not limited to adding only packages to which conda has access to your new environment. Here's an example on how to install a commonly desired GIS-related package (shapely) into a conda virtual environment using the python pip utility:
http://deparkes.co.uk/2015/01/29/install-shapely-on-anaconda/
This can most easily be done (personal opinion) with a Python usercustomize.py startup script
Code Block | ||||
---|---|---|---|---|
| ||||
###########################################
# Edit here match your setup
# These paths must match your Anaconda setup exactly.
# Anaconda home folders
conda_arcmap_home = r"D:\Users\jwpowell\Miniconda2"
conda_arcmap64_home = r"D:\Users\jwpowell\Miniconda3x64"
conda_arcpro_home = r"D:\Users\jwpowell\Miniconda3x64"
# anaconda environments set up to match Desktop and Pro
conda_arcmap_env = "arc1041"
conda_arcmap64_env = "arc1041x64"
conda_arcpro_env = "arcpro13"
# ArcGIS Pro install folder
default_pro_path = r"C:\ArcGIS\Pro"
# change to false after testing done
debug = True
# do not edit below this line
########################################### |
Create a user-specific site packages folder and place the script in the folder with the name usercustomize.py.
The user site-packages folder path can be found with: python -m site --user-site
Usually: C:\Users\username\AppData\Roaming\Python\Python27\site-packages (ArcGIS Desktop)
C:\Users\username\AppData\Roaming\Python\Python34\site-packages (ArcGIS Pro, Python35 for Pro 2.0)
Code Block | ||||
---|---|---|---|---|
| ||||
:: Python 2.7
mkdir %APPDATA%\Python\Python27\site-packages
copy usercustomize.py %APPDATA%\Python\Python27\site-packages
:: Python 3.4
mkdir %APPDATA%\Python\Python34\site-packages
copy usercustomize.py %APPDATA%\Python\Python34\site-packages |
ArcGIS
print ("\n".join(sys.path)) -- you should see the Anaconda site-packages near the end of the list
Anaconda
activate arc1041 (or whichever environment in the list)
python
import arcpy
print ("\n".join(sys.path)) -- you should see the ArcGIS site-packages near the end of the list
How to do a separate Python installation with ArcGIS? (GIS Stack Exchange)
Using ArcPy with Anaconda (PyMorton)
Many thanks to Parker Norton for his reviews and excellent additions to this document!
Justin Mayers has posted a batch script to install and set up set up MiniConda and environments to interact compatibly with Esri desktop software (ArcMap and Pro).
USGS BWTST supports an Anaconda3 SCCM package. This could be installed and linked to Pro using the information in this document.
ArcGIS Pro 2.x and later sets up an Anaconda install of its own. This environment could also be leveraged in various ways as time goes on.