22

I am trying to follow the step-by-step directions in the answer to "how to separate Python installation with ArcGIS" but cannot find the path file, DTBGGP64.pth, in C:\Python27\ArcGIS10.2\Lib\site-packages.

Has someone has faced a similar issue?

I am wondering if there is a workaround by including a path file that tells Anaconda where arcpy is installed? I tried to create a .pth file containing the following text:

# .pth file for arcpy

C:\Program Files (x86)\ArcGIS\Desktop10.2\bin 
C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy
C:\Program Files (x86)\ArcGIS\Desktop10.2\Scripts

and saved it to C:\Anaconda\Lib\site-packages (that is, if this is indeed where all the packages are saved) but I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\__init__.py", line 21, in <module>
    from arcpy.geoprocessing import gp
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\geoprocessing\__init__.py", line 14, in <module>
    from _base import *
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 14, in <module>
    import arcgisscripting
ImportError: DLL load failed: %1 is not a valid Win32 application.

I am running conda 3.7-py27 on a windows 7 (64bit) platform. Anaconda is installed in C:\Anaconda and ArcMap is installed in C:\ArcGIS\Desktop10.2. Is there an alternative solution to get arcpy to work with Anaconda? I just want to be able to run my scripts from Powershell.

  • just to be sure - when you type 'python' at a cmd prompt - what version/install does it echo? (i.e. arcgis or anaconda?) - oops just saw this is a bit dated. prob solved by now. – fluidmotion Apr 18 '15 at 14:25
  • I heard from a developer at Esri UC that Anacondas will be built into ArcGIS 10.5. I would recommend just installing the modules you need otherwise it could get messy. – dgrubman Jul 20 '16 at 19:39
  • It looks like this ^ is the case from the ArcGIS 10.5 System Requirements – WxCZar Oct 24 '17 at 12:54
13

You're using a 64 bit version of Python in your Anaconda installation and ArcMap's Python is 32 bit. You'll need to install some 64 bit ArcGIS build (either 64 bit Background Geoprocessing or ArcGIS for Server) and point to that instead, or install a 32 bit Anaconda instance instead and try again. See the downloads page and get the 32 bit installer.

30

This tutorial shows you how to set up conda environment to work with ArcGIS 10.4 and ArcGIS Pro 1.3.

Workflow to set up Anaconda with ArcGIS 10.4

  • Install Anaconda without fouling the Windows environment (paths, registry) to break Esri's python stack
  • Configure Anaconda with the particular add-ons you want, and
  • Configure ArcGIS's Python so that it is aware of the appropriate Anaconda content.

1) Install Anaconda for All Users

  1. Go to http://continuum.io/downloads
  2. Download the 32-bit version of Anaconda (Python 2.7)
  3. In the install dialogs:
    • Select install for All Users
    • Install to a folder by default (C:\Anaconda2)
    • IMPORTANT: To avoid breaking ArcGIS (or other software), uncheck the checkboxes (a) make Anaconda the default Python and (b) add Anaconda's Python to the PATH.
  4. Go to Start > All Programs(apps) > Anaconda2(32-bit) > Anaconda Prompt. Right click, run as administrator

2) Configure an Anaconda environment for use with ArcGIS

  1. Find the versions of numpy and matplotlib ArcGIS is using.
Open ArcMap and its Python window, and enter these commands:

    • >>> import sys, numpy, matplotlib
    • >>> print(sys.version, numpy.__version__, matplotlib.__version__)
    • ('2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)]', '1.9.2', '1.4.3')
  1. Create an Anaconda environment that is compatible with ArcGIS
    • Get to the Anaconda Command Prompt (Start > All Programs(apps) > Anaconda2(32-bit), pick "Anaconda Prompt"), Right click, Run as Administrator.
    • Type (depending on ArcGIS version, I am using ArcGIS 10.4 as an example here):
    • "conda create -n arc104 python=2.7.10 numpy=1.9.2 matplotlib=1.4.3 pyparsing xlrd xlwt pandas scipy ipython ipython-notebook ipython-qtconsole"
    • Enter y to proceed.
    • Anaconda's conda command will then set up an environment subdirectory, ex: " C:\Anaconda2\envs\arc104 ", installing the downloaded packages into it.
  2. Test the virtual environment
    • At the Anaconda Command Prompt, type: activate arc104
    • Type: conda list. You can see the list of packages installed.
  3. Add more packages
    • 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 Python Spatial Analysis Library (pysal) module.
    • Type the following command at the Anaconda Prompt:"conda install -n arc104 python=2.7.10 numpy=1.9.2 matplotlib=1.4.3 pysal"

3) Configure ArcGIS to see Anaconda and vice versa

  1. Anaconda Python to ArcPy
    • Copy the Desktop10.4.pth file to the Anaconda environment site-packages folder:
    • From: C:\Python27\ArcGIS10.4\Lib\site-packages\Desktop10.4.pth
    • To: C:\Anaconda2\envs\arc104\Lib\site-packages\Desktop10.4.pth
  2. Arcpy to Anaconda Python
    • Create a zconda.pth (path) file with the content "C:\Anaconda\envs\arc104\lib\site-packages" in it.
    • Then copy zconda.pth to C:\Python27\ArcGIS10.4\Lib\site-packages
  3. Testing in ArcMap
    • As a regular user, start ArcMap, open the Python window
    • type "import pysal"
    • type "pysal." A popup menu with a list of pysal-provided functions is a pretty good sign the installation succeeded.
  4. Testing in PyCharm
    • Start PyCharm, in File\Settings…, choose Project then Project Interpreter
    • Ignore the drop down list for Project Interpreter, and click the cog button to Add Local, and in the file browser pick C:\Anaconda2\envs\arc104\python.exe
    • To run your script, right click it in the Project window, and choose either Run or Debug
    • Restart PyCharm for the Python Console to use the arc104 environment.

Workflow to set up Anaconda with ArcGIS Pro 1.3

1) Create an Anaconda environment that is compatible with ArcGIS Pro

  • Copy the folder arcgispro-py3 from C:\Program Files\ArcGIS\Pro\bin\Python\envs and paste to C:\Anaconda2\envs
  • Rename the copied folder arcgispro-py3 in C:\Anaconda2\envs to arcpro

2) Test the virtual environment

  • At the Anaconda Command Prompt, type: activate arcpro
  • Type: conda list. You can see the list of packages installed

3) Add more packages

  • Let's add the Python Spatial Analysis Library (pysal) module.
  • Type the following command at the Anaconda Prompt:"conda install pysal"

4) Configure ArcGIS to see Anaconda and vice versa

  • Anaconda Python to ArcPy
    • Edit the ArcGISPro.pth (path) file within "C:\Anaconda2\envs\arcpro\lib\site-packages".
    • Change the relative ArcPy path to C:\Program Files\ArcGIS\Pro\Resources\ArcPy
    • Change the relative ArcToolBox path to C:\Program Files\ArcGIS\Pro\Resources\ArcToolBox
  • Arcpy to Anaconda Python
    • Create a zconda.pth (path) file with the content "C:\Anaconda2\envs\arcpro\lib\site-packages" in it.
    • Then Copy zconda.pth to C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages
  • Testing in ArcGIS Pro
    • Start ArcGIS Pro, open the Python window
    • type "import pysal"
    • type "pysal." A popup menu with a list of pysal-provided functions is a pretty good sign the install succeeded.
  •  Testing in PyCharm
    • Start PyCharm, in File\Settings…, choose Project then Project Interpreter
    • Ignore the drop down list for Project Interpreter, and click the cog button to Add Local, and in the file browser pick C:\Anaconda2\envs\arcpro\python.exe
    • To run your script, right click it in the Project window, and choose either Run or Debug
    • Restart PyCharm for the Python Console to use the arcpro environment.

References

  1. https://goo.gl/pOyLA9
  • This all works great, Anaconda packages are inside ArcGIS and vice-versa but I have a remaining issue. If I try and do an import arcpy and then arcpy.Describe on a RDBMS(Oracle)-sourced featureclass in Anaconda then I get IOError:...does not exist. Works fine on a filegeodatabase featureclass but will not seemingly connect to Oracle (e.g. arcpy.Describe(r'C:\temp\password_saved_sde_file.sde\EDGIS.ElectricDataset\EDGIS.Anchor')). – Phil Penn May 17 '18 at 18:23
7

To address this, browse to the python27\Lib\site-packages folder, mine was located under "C:\Python27\ArcGIS10.1\Lib\site-packages", and find the file Desktop10.1.pth.

On my system, the problem was resolved by simply copying the Desktop10.1.pth file into "C:\AppData\Local\Continuum\Anaconda\Lib\site-packages".

If you are running Anaconda 64 bit, you will get a different error when you try to import arcpy because ArcGIS runs 32 bit. Therefore, you have to make sure that you have the Anaconda 32 bit installed rather than 64 bit so things match up with ArcGIS. Once the file is copied and you have Anaconda 32 bit, import arcpy should work.

3

If you installed Arc before Anaconda, your default IDLE, Python Window (in Arc), and Python console will always pull from your Arc-installed modules, i.e. C:\Python27\ArcGIS <version>\Lib (and/or) Lib\site-packages. If you have packages installed with Anaconda that you want to use with Arc's install of Python you'll need to write .pth files in order to share between Python installs (light reading).

For example, I wanted to use the pandas package from my Anaconda stuff. I made a text file in my Arc's site-packages folder called anaconda.pth with the contents of C:\Anaconda\Lib\site-packages to link the Arc-install to the Anaconda site-packages. Now, I could import pandas inside of the Arc-installed Python without an ImportError. (If you have trouble with numpy, rename the Arc-installed numpy folder to _numpy).

On the flipside, copy and paste the Desktop<version>.pth file from the Arc site-packages folder into your Anaconda's (that specifies the actual location of the arcpy package), and make another .pth file that points to your Arc site-packages folder in your Anaconda's so you can use Arc's packages from Spyder if you use it.

2

Another user asked a similar question on github, which might be of interest to you. Here's the gist of what one user recommended to import arcpy autocompletion data for anaconda:

DamnWidget commented on Feb 26 https://github.com/DamnWidget/anaconda/issues/284

Open a PowerShell or CMD.exe and go to your anaconda installation under the Packages folder in your Sublime Text 3 %APPDATA%. CD into the anaconda_lib folder and start an interactive Python interpreter on that path.

Copy and paste the following:

import jedi

print(jedi.Script('import arcpy; arcpy.').completions())

Then (at least for me) it returned a bunch of stuff in the cmd window, and it seemed to have worked. I re-opened Sublime Text and it pulls up autocomplete for arcpy functions.

My problem is that is takes 5+ seconds to load them, it seems to never keep arcpy loaded in memory for more than a few seconds. But that's a different issue I think...

1

You should just install the 32 bit version of Anaconda.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

protected by Community Apr 4 '18 at 14:39

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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