ArcGIS, General, Python

Enable Python installations that were not installed by ArcGIS to access Arcpy functionality

ArcGIS installs its own version of Python that is not officially registered with the system but can in reality be used just like a normal install. I personally prefer just to use this as my primary Python, but it is not always possible. The instructions below can help you let a different Python install access and use Arcpy, for example the Python installed by Python(x,y). Note that:

  • the major versions must match (2.6 for ArcGIS 10.0 and 2.7 for ArcGIS 10.1)
  • the architecture (32 bit or 64 bit) must match (see the start of this post for information on determining Python version and architecture)
  • if you write scripts and use these as script tools within Arc they will use the Python installed by Arc; this means that any libraries you have installed to the other Python, but not installed to the ArcGIS Python, will be inaccessible (causing an ImportError)

Python looks for libraries in certain folders (i.e. the Lib\site-packages\ folder of the install), and when you type import somelibrary it looks for a file by the name of somelibrary.py in these folders. The Arcpy files are actually located in the ArcGIS install folder, in Program Files, but a path file is placed in the Lib\site-packages\ folder that tells Python to also browse through the relevant ArcGIS folders for files when you go to import libraries.

To allow other Python installations to access Arcpy this path file simply needs to be copied from the Lib\site-packages\ folder within the Arc Python installation and placed in the corresponding folder of the non-Arc Python. If you have not installed 64-bit background geoprocessing the file is Desktop10.1.pth; if you have installed it, the file is DTBGGP64.pth.

As an aside: as far as I know it is not possible to move the Python that is installed by ArcGIS. Uninstalling and reinstalling ArcGIS should allow you to change the Python install location, except in the case of some silent network installs.

Advertisements

5 thoughts on “Enable Python installations that were not installed by ArcGIS to access Arcpy functionality

  1. Hi Stacy,

    Up until yesterday my ArcGIS 10.3.1 was working perfectly. I was working on something else outside of ArcGIS and I had to install Python XY with a GDAL extension on it. Before installing Python XY, I was warned that I already have Python 2.7 on my PC and that it might cause a problem. I ignored the warning because I didn’t want to remove or mess up the way ArcGIS is configured on my PC. After the Python XY installation, I now have problems with starting up my ArcGIS. The following error message appears 27 times when I try to startup ArcGIS (now that Python XY is installed):
    “DDE Server Window: ArcMap.exe System Error
    The program can’t start because cares-90-mt.dll is missing from your computer. Try reinstalling the program to fix this problem”

    I tried uninstalling Python XY but then ArcGIS doesn’t work at all, so I reinstalled Python XY again. Something has changed due to the installation of Python XY and I don’t know how to change back. Do you have any suggestions apart from reinstalling ArcGIS 10.3.1 from scratch?

    Thank you for the blog

    1. Hi Alistair. I can’t find anything online regarding cares-90-mt.dll, are you sure that is the correct name (no spelling mistakes, etc.)? I think you will have to reinstall ArcGIS 10.3.1, sorry! Possibly uninstall ArcGIS, install PythonXY first, then install ArcGIS again – might help, or could cause PythonXY not to work… Do you really need PythonXY? In my experience these packages are so big and have so many components that something often goes wrong – can you get by with installing some packages onto Arc’s Python?

      1. Hi Stacy,

        Thank you getting back to me. Yes the name is correct and without spelling mistakes. I don’t actually need Python XY – it was just the GDAL part which I needed (or thought I needed). I’ll try to do as you say and reinstall ArcGIS. Thank you for your help,

  2. Someone else very kindly helped me. This is the solution:

    “Python XY overwrote the PYTHONPATH variable which tells Windows where to find Python and its modules. Since ArcGIS comes with its own Python, changing the PYTHONPATH to a different Python version/location will prevent ArcGIS from importing the modules/DLLs it needs as it will look for them in the Python XY folder (which does not contain them).

    You can edit the PYTHONPATH and point it to esri’s Python by hand but that’s error prone. Luckily, the ArcGIS installer allows you to reinstall esri’s Python without touching other ArcGIS components, see

    http://www.esri.ca/en/content/how-do-i-reinstall-python-components-arcgis-desktop.

    The Python2x folder mentioned in step 6 is located on your C: drive.”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s