Arcpy fails to import in Spyder

1598
4
10-02-2018 08:41 AM
JoeBorgione
MVP Emeritus

Today I'm working in Spyder just like any other day but when I try to import arcpy, I get this:

import datetime

import os

import arcpy
Traceback (most recent call last):

  File "<ipython-input-3-5467a3dc9fe3>", line 1, in <module>
    import arcpy

  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\__init__.py", line 72, in <module>
    from arcpy.geoprocessing import gp

  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\__init__.py", line 14, in <module>
    from ._base import *

  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 14, in <module>
    import arcgisscripting

RuntimeError: Not signed into Portal.‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I imported datetime & os just to see if they worked okay and they do;  I get this error if I let the console window sit long enough. I'm curious what the connection is with arcpy, spyder, python and Portal/ArcGIS Online is and how I can avoid this in the future....

eta moments later....  Shut down spyder and reopened it: cured.... (?)

That should just about do it....
0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

Happened to me, once or twice... waiting and/or rebooting fixed the issue:

import os

import datetime

from arcpy.geoprocessing import gp

dir(gp)[:3]
['__class__', '__delattr__', '__dict__']

You will have to follow the long and circuitous path in your installation path to arcpy

C:\Your_path_to_arcgis_pro\Resources\ArcPy\arcpy  which contains Bin, Resources and Support

the __init__.py files starts the imports, which imports stuff... including _base.py amongst others.

You can follow the trail which generally leads to a dead end (ie *.pyd files usually) and try to figure out why any connection would be needed.

In short... you probably shouldn't know or want to know.  I have explored some of this /blogs/dan_patterson/2018/09/26/import-arcpy-what-happens to check namespace, load time and bloat issues when just importing arcpy

DanPatterson_Retired
MVP Emeritus

resolved?

0 Kudos
JoeBorgione
MVP Emeritus

Restart.  (note my edit moments later...)

That should just about do it....
0 Kudos
DanPatterson_Retired
MVP Emeritus

0 Kudos