"management" is not a known member of module "arcpy" Pylance(report GeneralTypeIssues)

180 Views Asked by At

I am new to using vscode with python.exe for arcgispro. My interpreter is set to the arcgispro-py3-env\python.exe.

I would like to be able to run python code within vscode but I am running into some issues with pylance, which does not seem to recognize arcgis functions or able to set my working directory.

For example when I try to set my working directory to env.workspace = wd

I get the following error:

Cannot assign member "workspace" for type "GPEnvironment" 
     Pylance(reportGeneralTypeIssues) Member "workspace" is unknown

Or when I try to execute the following code arcpy.management.Project, I get the following error:

"management" is not a known member of module "arcpy" 
     Pylance(reportGeneralTypeIssues)

I don't want to use the #type:ignore fix as this will be cumbersome with lots of code.

1

There are 1 best solutions below

1
Thomas On

Easiest way to avoid a Pylance error is to add import arcpy.management:

import arcpy
import arcpy.management  # <- import arcpy.management explicitely

arcpy.management.CreateFeatureclass(
     r"c:\temp", "buildings.shp", spatial_reference=arcpy.SpatialReference(4326))

The reason is most likely that arcpy.management is unkonwn to arcpy/__ini__.py.

As for arcpy.env.workspace, looking at the auto-completion, arcpy.env seems to be some sort of dictionary class:

enter image description here

With this knowledge, you could use the [] operator to avoid a Pylance error. For example:

import arcpy
import arcpy.management

arcpy.env["overwriteOutput"] = True  # <- using [] operator instead

arcpy.management.CreateFeatureclass(
     r"c:\temp", "buildings.shp", spatial_reference=arcpy.SpatialReference(4326))