When I try to import arcpy into the python window in ArcGIS Desktop and I am given this ImportError.

>>>import arcpy 

Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\program files (x86)\arcgis\desktop10.\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 592, in <module>
    env = GPEnvironments(gp)
  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 589, in GPEnvironments
    return GPEnvironment(geoprocessor)
  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 542, in __init__
    import weakref
  File "C:\Users\dayl\AppData\Local\Continuum\anaconda2\Lib\weakref.py", line 14, in <module>
    from _weakref import (
ImportError: cannot import name _remove_dead_weakref
  • Sometimes having Anaconda installed on the same system as ArcGIS causes issues. I haven't seen this particular error but worked around similar import issues using the archook package. – smiller May 1 '18 at 19:15
  • I would reinstall arcgis – atxgis May 1 '18 at 19:17
  • 1
    Possible duplicate of Changing which python ArcGIS uses? – Squanchy Oct 11 '18 at 16:04

I think there's a conflict in which version of Python is being called - the default that comes with ArcGIS 10.2, or your Anaconda installation.

Aside from using the archook package, @Qiusheng Wu's detailed tutorial for setting up ArcGIS and Anaconda seems like a good start to resolve this import issue.


ArcMap defaults to C:\Users\dayl\AppData\Local\Continuum after anaconda is installed.

Rename the Continuum fodler

C:\Users\dayl\AppData\Local\Continuum to C:\Users\dayl\AppData\Local\Continuumx

Now import arcpy should work.

Update your System Environment PATH

Since we renamed the Continuum folder we should update any paths that use it.

  1. Go to your System Properties
  2. Click the Advanced tab.
  3. Click Environment Variables.

In my case I had to update my conda path variable

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