Select to view content in your preferred language

Cannot import 'Layer' from arcgis.mapping

1325
3
Jump to solution
07-04-2023 06:03 AM
Labels (1)
Sfortunatamente
Occasional Contributor

Hi,

I am working on a simple script which copies a web map and adds a new layer:

from arcgis.gis import GIS
from arcgis.mapping import WebMap
from arcgis.mapping import Layer

I receive:

ImportError: cannot import name 'Layer' from 'arcgis.mapping' (C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\mapping\__init__.py)

ArcGIS Pro 3.1.1

What is wrong?

Thanks.
-b.

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Alum

There is no class Layer in arcgis.mapping .

 

Here are some classes that could be what you want:

 

for x in arcgis.mapping.__dict__.keys():
    print(x)

 

...
MapImageLayer
MapImageLayerManager
...
VectorTileLayer
...
Object3DLayer
IntegratedMeshLayer
Point3DLayer
VoxelLayer
PointCloudLayer
BuildingLayer
SceneLayer
...
MapServiceLayer
MapFeatureLayer
MapTable
MapRasterLayer
...

 

It's also possible that you actually want arcpy.mp.Layer ...

 


Have a great day!
Johannes

View solution in original post

0 Kudos
3 Replies
JohannesLindner
MVP Alum

There is no class Layer in arcgis.mapping .

 

Here are some classes that could be what you want:

 

for x in arcgis.mapping.__dict__.keys():
    print(x)

 

...
MapImageLayer
MapImageLayerManager
...
VectorTileLayer
...
Object3DLayer
IntegratedMeshLayer
Point3DLayer
VoxelLayer
PointCloudLayer
BuildingLayer
SceneLayer
...
MapServiceLayer
MapFeatureLayer
MapTable
MapRasterLayer
...

 

It's also possible that you actually want arcpy.mp.Layer ...

 


Have a great day!
Johannes
0 Kudos
Sfortunatamente
Occasional Contributor

Thanks a lot! I should be more careful with AI then..

-b.

hershy1234
New Contributor

What do you mean AI? It's the ArcGIS documentation that shows code snippets that error.

`ImportError: cannot import name 'WebMap' from 'arcgis.mapping'`

from arcgis.mapping import WebMap, WebScene

 

https://developers.arcgis.com/python/latest/samples/publishing-web-maps-and-web-scenes/

 

0 Kudos