Anaconda: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
Brian Wilson (talk | contribs)
Line 107: Line 107:
and unzip it
and unzip it


=== Windows + ArcGIS 10.6 ===
=== Windows + ArcGIS 10.7 ===
 
Miniconda downloader: https://conda.io/en/latest/miniconda.html


Read this ''before'' plunging into the Anaconda installer.  
Read this ''before'' plunging into the Anaconda installer.  
Line 117: Line 119:
'''Why install 64-bit Anaconda?''' Same reason, but also so that you can work in a completely up to date and snazzy Anaconda  
'''Why install 64-bit Anaconda?''' Same reason, but also so that you can work in a completely up to date and snazzy Anaconda  
environment that has acess to the ESRI python modules (and therefore all of the ESRI ecosystem.)
environment that has acess to the ESRI python modules (and therefore all of the ESRI ecosystem.)
I installed Anaconda2 in the VM that I use for ArcGIS Desktop


NB:
NB:
Line 125: Line 125:
* I told it NOT to modify my PATH and NOT to change the registry, so that the versions already installed by ESRI will continue to work.
* I told it NOT to modify my PATH and NOT to change the registry, so that the versions already installed by ESRI will continue to work.
* I installed for "Just me" because I am the only one who ever uses this computer.
* I installed for "Just me" because I am the only one who ever uses this computer.
 
* I never double-click py files to run them so I don't need to change the registry.
I never double-click py files to run them so I don't need to change the registry.
* For speed, I used /c/Users/bwilson/Continuum as the folder. When we get new computers next month I will need to reinstall it.


In each environment then
In each environment then
Line 132: Line 132:
Start a 32-bit conda prompt
Start a 32-bit conda prompt
  conda update conda
  conda update conda
  conda create -n arc1051
  conda create -n arc10
  activate arc106
  activate arc10
  conda install  python=2.7.14 numpy matplotlib=1.5.3  scipy=0.17.0 pandas pyparsing xlrd xlwt console_shortcut spyder
  conda install  python=2.7.15 numpy matplotlib=1.5.3  scipy=0.17.0 pandas pyparsing xlrd xlwt console_shortcut spyder
You can add a bash shell here too.
You can add a bash shell here too.
  conda install -c msys2 m2-bash
  conda install -c msys2 m2-bash


Start a 64-bit conda prompt
Start a 64-bit conda prompt
  conda create -n arc106x64
  conda create -n arc10x64
  activate arc106x64
  activate arc10x64
  conda install  python=2.7.14 numpy matplotlib=1.5.3  scipy=0.17.0 pandas pyparsing xlrd xlwt console_shortcut spyder
  conda install  python=2.7.15 numpy matplotlib=1.5.3  scipy=0.17.0 pandas pyparsing xlrd xlwt console_shortcut spyder
  conda install -c anaconda git
  conda install -c anaconda git



Revision as of 19:27, 16 May 2019

Anaconda is a Python based platform that is available on MacOS, Windows and Linux. It uses a package management utility called conda.

It's installed as part of ESRI ArcGIS Pro so if you have that then you don't need to install it separately.

You can install a gigantic everything-including-the-kitchen-sink version called Anaconda that includes 100's of packages or a more fleet-footed version called miniconda and then install just the packages you need.

I used to install miniconda primarily to get spyder, which is a reasonably good IDE and debugger. These days I do most of my Python work on Windows 10 so I use Microsoft Visual Studio.

Suggestions

Disclaimer: I work mostly in a Windows 7 environment and use ArcGIS Desktop 10.6, ArcGIS Enterprise, and sundry open source packages. At home I use mostly open source on Mac, Linux and Windows 10. If life is different for you these notes might not be relevant.

Don't install Anaconda, it's very big, install miniconda then add the packages you will actually use. Here is the Miniconda download page.

Don't install the "workloads" for Python and Anaconda that come from Microsoft with Visual Studio either! If you do then you will need administrative rights every time you want to update or install a package. If you install Miniconda as yourself (not admin) then you can maintain the packages yourself logged in as a normal user. Still worse is the process for removing a Python environment that was automatically installed from Visual Studio. Just don't do it. Trust me.

Anaconda is convenient if you want to do one giant install and have most everything you need, but it takes a long time to download the 300 or so packages it installs and chances are you will use only a few of them.

I tried "Jupyter notebook" because ESRI's pushing it these days and found Spyder to be a far better match for my needs.

I installed Anaconda on Plover (a MacBook) first, I can't access the ESRI "ArcPy" module from OS/X but I can use the "ArcGIS" module. ArcPy is for desktop GIS work. ArcGIS is for talking to ArcGIS Online.

I learned about using Jupyter notebook by watching an ESRI video, "ArcGIS API for Python: Advanced Scripting". I like the idea of cells and being able to visualize data directly (like displaying a dataset on a map) but I never need to do that.

Running this code in Spyder generates an error about Javascript. Running it in Jupyter generates a map, because it will send javascript to your browser.

from arcgis.gis import GIS
g = GIS()
g.map()

Installation

Windows

2018-May-09 I installed version 3 at work today, 32- and 64-bit.

2018-Jan-25 I have it installed on Windows 7 at work and on Windows 10 at home.

Linux

2017-Jul-09 Laysan Ubuntu. Installed miniconda3, then "conda3 install spyder" and "conda3 install -c esri arcgis"

Mac

2017-May-13 Installing on Plover

Download the Miniconda installation shell script and run it. Say "yes" to modifying your PATH.

I am not putting Anaconda onto Stellar, because alas Apple won't update the operating system for her and Anaconda warns against using old versions of OS/X.

Create an environment for doing GIS work, thus keeping all the modules contained.

conda create -n gis
source activate gis
conda install spyder
conda install gdal # This installs lots of related packages
conda install -c esri arcgis # this installs ESRI's python api module, "arcgis".

When you do 'which spyder' it should show the one installed in the gis environment, for me it's

/Users/bwilson/miniconda3/envs/gis/bin/spyder

Installing spyder inside the "gis" environment avoids having to mess around with settings and does not pollute the base install with things like alternative versions of numpy and python.

Installing spyder also installs jupyter.

Windows + Python + GDAL + FGDB

I still don't have the FGDB part working but I don't really care any more since I saw the comment in the docs that it can't be used with Annotation Feature Classes. I guess that leave me with trying to get access via ArcObjects.

See also https://github.com/OSGeo/gdal and https://trac.osgeo.org/gdal and of course http://www.gdal.org/

Download the WHL file you need from https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal The one you need matches your bitness (64-bit) and your python version so 64 + Python 3.6 = GDAL?2.2.3?cp36?cp36m?win_amd64.whl for me.

So far... at an Anaconda 64 bit prompt

conda create -n gdalwhl
activate gdalwhl
conda install pip
pip install GDAL?2.2.3?cp36?cp36m?win_amd64.whl

Test before going on

python
import osgeo.gdal
gdal.__version__

should show

'2.2.3'

Download the FGDB zip from Github, https://github.com/Esri/file-geodatabase-api/tree/master/FileGDB_API_1.5.1 and unzip it

Windows + ArcGIS 10.7

Miniconda downloader: https://conda.io/en/latest/miniconda.html

Read this before plunging into the Anaconda installer. https://my.usgs.gov/confluence/display/EGIS/Using+Anaconda+modules+from+the+ESRI+python+environment

Why install 32-bit Anaconda? So that you can use the Anaconda environment to add and maintain python packages. Arguably you could replace the entire ESRI Python with Anaconda Python but I don't suggest doing this.

Why install 64-bit Anaconda? Same reason, but also so that you can work in a completely up to date and snazzy Anaconda environment that has acess to the ESRI python modules (and therefore all of the ESRI ecosystem.)

NB:

  • I installed both the 32- and 64-bit versions, so that I can use both ArcMap and geoprocessing.
  • I put the 32-bit version in Miniconda2_32 and the 64-bit version in Miniconda2_64
  • I told it NOT to modify my PATH and NOT to change the registry, so that the versions already installed by ESRI will continue to work.
  • I installed for "Just me" because I am the only one who ever uses this computer.
  • I never double-click py files to run them so I don't need to change the registry.
  • For speed, I used /c/Users/bwilson/Continuum as the folder. When we get new computers next month I will need to reinstall it.

In each environment then

Start a 32-bit conda prompt

conda update conda
conda create -n arc10
activate arc10
conda install  python=2.7.15 numpy matplotlib=1.5.3  scipy=0.17.0 pandas pyparsing xlrd xlwt console_shortcut spyder

You can add a bash shell here too.

conda install -c msys2 m2-bash

Start a 64-bit conda prompt

conda create -n arc10x64
activate arc10x64
conda install  python=2.7.15 numpy matplotlib=1.5.3  scipy=0.17.0 pandas pyparsing xlrd xlwt console_shortcut spyder
conda install -c anaconda git

I do some things with PDF files so I installed this

conda install -c anaconda-nb-extensions pypdf2

Likewise I want to be able to read Excel .xlsx files.

conda install -c anaconda openpyxl 

You can add a bash shell here too.

conda install -c msys2 m2-bash

The process of setting up the environment should create items in your Startup menu with the environment name appended, use those to get access to arcpy.

The version of Python that launches from ArcGIS will be the same one ESRI installed but it will have access to packages that you install in the arc1051 environment in Anaconda because of the 'zconda.pth' file. Naming it with a 'z' means it loads last and therefore most packages (like scipy and numpy) load from the ESRI directory and only things you have added come from Anaconda.

USGS missed only one item in there-- the 32-bit pth file to copy is Desktop.pth but the 64-bit file is DTBGGP64.pth which I assume stands for "DeskTop BackGround GeoProcessing 64-bit".

cd /c/Python27/ArcGISx6410.5/Lib/site-packages
cp DTBGGP64.pth /c/Users/bwilson/AppData/Local/Continuum/miniconda2_64/envs/arc1051x64/Lib/site-packages/

ArcGIS module

In the 64-bit environment (miniconda3)

conda update conda
conda create -n arcgis
conda activate arcgis
conda install python
conda install -c esri arcgis

This works, now I can connect to my ArcGIS Enterprise Portal to test the connection. This 3 line test will prompt me for a password and then print the properties.

from arcgis.gis import GIS
gis = GIS("http://flyingsquirrel.wildsong.biz/portal", username="bullwinkle")
print(gis.properties)

Windows + ArcGIS Pro

With AGP, ESRI installs python3 and conda for you but does not update your PATH. They probably tell you how to do that somewhere. They install it with admin permissions so (as with Microsoft Visual Studio Workloads) you can't change it for example to add packages unless you have admin access. What you CAN do is clone the environment, leaving the ESRI one untouched, and then use the clone.

At version 2.2 of AGP you could have this in your environment

CONDAHOME=C:\Program Files\ArcGIS\Pro\bin\Python

and add this to PATH so that apps can find conda.exe: %CONDAHOME%\Scripts

Once your path is fixed up you can run a cmd window and use conda to create a new writable environment

conda create -n my_arcgispro-py3 --clone="%CONDAHOME%\envs\arcgispro-py3"

List the available environments

conda info --envs
# conda environments:
#
my_arcgispro-py3         C:\Users\bwilson\AppData\Local\ESRI\conda\envs\my_arcgispro-py3
arcgispro-py3         *  C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3
root                     C:\Program Files\ArcGIS\Pro\bin\Python

Switch to the new environment and install gdal there.

activate my_arcgispro-py3
conda install gdal

This installs the gdal packages (along with about 30 dependencies and 20 updates) into my_arcgispro-py3 environment. AGP will continue to use the old environment but I don't care because I normally work in Visual Studio and shell windows anyway.

You can list the packages installed. You should see the correct environment path and arcgispro 2.2 listed in there.

conda list
# packages in environment at C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3:
#
arcgis                    1.4.1            py36h52c3b5e_1    esri
arcgispro                 2.2                           0    esri
asn1crypto                0.24.0                   py36_0
attrs                     17.4.0                   py36_0
backcall                  0.1.0                    py36_0
... etc etc.
freetype                  2.8                      vc14_0  [vc14]  esri
freexl                    1.0.5                hfa6e2cd_0
future                    0.16.0                   py36_1    esri
gdal                      2.2.2            py36hcebd033_1                      <<<<---- YAY!!!
geos                      3.6.2                h9ef7328_2
...

Some old information is here: https://geonet.esri.com/groups/arcgis-python-api/blog/2017/02/08/arcgis-api-for-python-101-released

ArcGIS Pro + Visual Studio

If you are using VS older than 15.7, UPDATE NOW. Then read this page about environments and Conda in VS.

You can select environments in the Solution Explorer in Python Environments. Right click Python Environments and select "View all Environments" and the one we cloned should be listed. You can open an interactive window and type

import arcpy
import osgeo.gdal

and (if you have install gdal) it should not give any messages.

Select the environment, and Intellisense for arcpy and gdal should start working.

(Note that I have some extra environments that I set up when experimenting.)

Intellisense

In Python Environments, it says it no longer needs the Intellisense database and it's turned off. At first Intellisense did not work so I turned the database thing back on, but that was far worse so I turned it off and after a few restarts it appears to be working again.