Anaconda: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
Brian Wilson (talk | contribs)
Line 154: Line 154:
  cp DTBGGP64.pth /c/Users/bwilson/AppData/Local/Continuum/miniconda2_64/envs/arc1051x64/Lib/site-packages/
  cp DTBGGP64.pth /c/Users/bwilson/AppData/Local/Continuum/miniconda2_64/envs/arc1051x64/Lib/site-packages/


==== ArcGIS module =====
==== ArcGIS module ====


In the 64-bit environment (miniconda3)
In the 64-bit environment (miniconda3)
Line 164: Line 164:
  conda install -c esri arcgis
  conda install -c esri arcgis


This works, now I can connect to my ArcGIS Enterprise Portal. This
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.
3 line test will prompt me for a password and then print the properties.


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



Revision as of 18:32, 10 May 2018

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 Python and Anaconda versions 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.6

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.)

I installed Anaconda2 in the VM that I use for ArcGIS Desktop

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.

In each environment then

Start a 32-bit conda prompt

conda update conda
conda create -n arc1051
activate arc106
conda install  python=2.7.14 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 arc106x64
activate arc106x64
conda install  python=2.7.14 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

At home I am trying out ArcGIS Pro

With AGP, ESRI installs python3 and conda for you.

https://geonet.esri.com/groups/arcgis-python-api/blog/2017/02/08/arcgis-api-for-python-101-released

Somewhere they probably even tell you how to use it. Since conda is installed I should be able to install the other components, right?

Launch a Python prompt from Start menu as administrator and then I can use conda to install packages. For example, this installs the new web API "arcgis" not to be confused with "arcpy".

conda install -c esri arcgis

This is one way, it is still possible to install Anaconda separately if you want. (For example to get control over package maintenance as mentioned above.)