I recently uninstalled Anaconda due to a conflict with my pandas packages. I use to have it configured with my ArcGIS Pro Python 3.65 environment.

Now I want to reinstall it, but for my ArcGIS Desktop 10.5/ Python 2.7 environment. I need to have an environment that has both the arcpy , pandas, and arcgis libraries/mods in it (which my current 2.7/ArcMap 10.5 does).

How can I install Anaconda for 2.7 without overwriting or interfering with my current ArcGIS 10.5/ Python 2.7 environment AND set up my arcpy/arcgis/pandas within that new Anaconda environment?

If I wanted to copy my current Arc - Python 2.7 env folder, where would I find it (ex: C:\Python27\ArcGIS10.5)?

  • If all you need is the pandas included with the ArcGIS Desktop 10.5/ Python 2.7 environment, you don't really need the anaconda distribution. You could simply use pip install pandas. – Pdavis327 Nov 8 at 20:47
up vote 3 down vote accepted

I am going to show how you can replicate arcgis' python enviroment using conda and then plug arcpy to it. This enviroment shall be isolated from arcgis' python so whatever changes do to it, it shouldn't affect arcgis.


The first step is to create an enviroment to enable arcpy at. You can do this with anacoda by typing in the anaconda promt:

 conda create -n arcpy python=2.7

This will create a new enviroment within anaconda called arcpy.

Next you need the default packages the come with Arcgis' python. To find them open your arcgis program and in the python promt type:

 >>> from pip.operations import freeze
 >>> packages = freeze.freeze()
 >>>for p in packages:
         print(p)

  cycler==0.10.0
  functools32==3.2.3.post2
  future==0.15.2
  matplotlib==1.5.2
  ....

Save this to a file and make a note of its name as we are going to use it in the next step. For convienience here I am posting my output. I saved them to a file called arcgis_10.5_req.txt.

NB. please remove the version number for functools32. Also note that the default arcgis' numpy version is 1.9.3.. You might need to change toto 1.10 as conda finds 1.9 to be conflicting with scipy.

Next activate your conda enviroment and using condas' installer, install the before mentioned packages:

conda activate arcpy
conda install --file arcgis_10.5_req.txt

After the procedure completes, open your Arcgis' python directory and site-packages folder (..\Lib\site-packages) should be one *.pth file. Copy that file into your anacondas' arcpy enviroment site-packages folder.

in my machine it was :

C:\Python27\ArcGISx6410.5\Lib\site-packages\DTBGGP64.pth -> D:\Miniconda3\envs\arcpy\Lib\site-packages\DTBGGP64.pth

The *.pth file contains a number of extra folders for python to look for modules or objects.

Alternatively if don't want to copy the .pth file you can at the start of your script add the folders found in the .pth file to the sys.path manualy at each start.

>>> import sys
# or sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.5\bin')
>>> sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.5\bin64')
>>> sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy')
>>> sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcToolBox\Scripts')

Now you should be able to call arcpy from this env:

conda activate arcpy
python

>>> import arpcy
>>> shp = 'my_shapefile.shp'
>>> with arcpy.da.SearchCursor(shp,['OID@','SHAPE@AREA']):
     for row in cursor:
      print('Feature {} has an Area of {}').format(row[0],row[1])
Feature 0 has an area of 0.13687430446
....
  • OK, additional question: I am trying to create an environment that matches my ArcGIS 2.7 env as you suggested. My matplotlib version is 1.5.2 but when I try to add that when creating the environment, I get "PackagesNotFoundError: The following packages are not available from current channels: matplline=1.5.2:" Is there a way around this? – gwydion93 Nov 9 at 14:31
  • 1
    check conda-forge they should have it. anaconda.org/conda-forge/matplotlib/… . To enable the conda-forge channel just add -c conda-forge when you try to install the packages. – nickves Nov 9 at 14:48
  • OK, for some reason, after I activate the new env and run conda list, I get this err: EnvironmentLocationNotFound: Not a conda environment:. What going on here? – gwydion93 Nov 9 at 15:26
  • This error has to do with your conda installation not with this procedure. Try opening your anaconda prompt, and type 'conda env list` do you see your new arcpy env? if you do, try to activate it now from there conda activate arcpy. – nickves Nov 9 at 15:34
  • 1
    yes what ever you do it's happening within this enviroment. As long you have activated it. You can verify it by typing pip show matplotlib, it should give you this ve's python. I you break it, just make a new one. I would suggest to make new ve based on that for per project. – nickves Nov 9 at 18:20

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.