Python IntelliSense in PyCharm w/ ArcPy Not Working

1201
5
05-11-2022 02:08 PM
VinceE
by
Occasional Contributor II

I cannot get intellisense to work with ArcPy's newer syntax style in Pycharm 2021.3.2 (Community Edition). What's odd is that the older-style syntax DOES work: arcpy.CreateFileGDB_management()

However, this does not: arcpy.management.CreateFileGDB()

To be clear, the code runs fine with the newer style. My interpreter is configured to point to ArcGIS Pro's Anaconda distribution (Python 3.7).

My assumption here is that PyCharm is somehow reading from the ArcGIS Desktop (Python 2.7) documentation, which is also installed on my system, but I can't find any references to that interpreter within PyCharm.

Any help would be greatly appreciated!

Tags (3)
0 Kudos
5 Replies
JoshuaBixby
MVP Esteemed Contributor

The same question was asked and answered over on GIS SE for VS Code:  VS Code Intellisense with modern arcpy syntax - Geographic Information Systems Stack Exchange.  I am guessing the answer for VS Code will work for PyCharm too.

VinceE
by
Occasional Contributor II

Thanks, it does, however this is a pretty clunky solution, and one that is not required in VS Code. My response to @Luke_Pinner below has a bunch of screenshots from the simple "import arcpy" working in VS Code.

This feels like a problem specific to PyCharm for whatever reason. Would love to hear if you have other ideas.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Possibly related to Autocomplete not working for lazily imported modules : PY-49357 (jetbrains.com).  The package tested in submitting the defect is similar to ArcPy in that autocomplete works in VS Code but not PyCharm.

Luke_Pinner
MVP Regular Contributor

@VinceE wrote:

My assumption here is that PyCharm is somehow reading from the ArcGIS Desktop (Python 2.7) documentation, which is also installed on my system, but I can't find any references to that interpreter within PyCharm.

No PyCharm (and VS Code) extract intellisense info from the code itself. And you only see top level info as the IDEs only look through the package you import, not sub-packages.

Just import arcpy.management and intellisense should work.

 

 

0 Kudos
VinceE
by
Occasional Contributor II

 

Interesting, thanks for the reply.

I might be misunderstanding you, but this is not my experience (at least in VS Code). Using VS Code, I have never imported arcpy.management, arcpy.analysis, arcpy.cartography, etc. in my tools.

I have also never seen reference to this import syntax in Esri documentation. This and the anecdotal evidence below make me skeptical that I need to "import arcpy.management".

In VS Code, intellisense from base arcpy import:

FromArcpy.png

also getting intellisense for management functions with this import style:

FromManagement.png

This is also not how other modules work, at least for me in VS Code. I don't import numpy.random for intellisense regarding "randint".

Numpy.png

or in PyCharm.

NumpyPyCharm.png

Would love to hear other ideas, if you have them. This feels like a PyCharm problem/setting, or something to do with the way ArcPy is written and interpreted by PyCharm, not an import style problem.