PyCharm – Importing ArcPy Installed with ArcGIS Pro

arcgis-proarcpypycharmpythonpython 3

I am trying to import arcpy in a script, which is running in a PyCharm environment using the Python 3.6.6 installation that comes bundled with ArcGIS Pro 2.3.2 as the base interpreter. I get the following error:

Traceback (most recent call last):
    File "C:/Users/lharris/PycharmProjects/general/test.py", 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
ImportError: DLL load failed: The specified module could not be found.

As per the only answer to Importing ArcPy in PyCharm? I have created a new PyCharm project using the Python install described above, which for my default installation is located here:

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe

Based on the answers to Why can't I import arcpy? and other similar issues, I have opened that Python interpreter on the command line, ensured that I can import arcpy (which I can) and then checked sys.path, which gives me:

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python36.zip
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\DLLs
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages
C:\Program Files\ArcGIS\Pro\bin
C:\Program Files\ArcGIS\Pro\Resources\ArcPy
C:\Program Files\ArcGIS\Pro\Resources\ArcToolbox\Scripts
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\future-0.16.0-py3.6.egg
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pytz-2018.5-py3.6.egg
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\sympy-1.2-py3.6.egg

I have created a .pth file in venv\Lib\site-packages that contains all of these paths. Without this file, the error given was "no module named arcpy" and with only 'C:\Program Files\ArcGIS\Pro\Resources\ArcPy' on the list, the error was "no module named arcgisscripting". With the complete list above, the error is the one I give at the beginning of this question.

Is there anything I've not tried that might help me to get arcpy imported in a Python 3 script in PyCharm using ArcGIS Pro?

Best Answer

You seem to be on the right track. On my computer I found the arcgisscripting library here:

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages

perhaps you could try your .pth file with just two entries:

C:\Program Files\ArcGIS\Pro\Resources\ArcPy C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages

see if that works for you. I'd try it myself, but I'm afraid I will mess up my ArcMap 10.6 python scripting environment in PyCharm.

Related Question