Select to view content in your preferred language

Unable to import arcpy via Pycharm

9236
8
09-28-2018 07:03 AM
VanceRenforth2
Occasional Contributor

I am trying to build python scripts in Pycharm to run in ArcGIS Pro 2.2.2. When I run a script which includes "import arcpy" I get the following Error message:

Traceback (most recent call last):
File "C:/Users/vmrenfor/Python Scripts/venv/Scripts/Dapp Uploads.py", line 2, in <module>
import arcpy
ModuleNotFoundError: No module named 'arcpy'

How do I get around this? I am a novice to python and the terminology that goes along with it, so please be specific and write out acronym meanings the first time you type it. 

0 Kudos
8 Replies
JoshuaBixby
MVP Esteemed Contributor

Please see my and Shaun Walbridge's replies to https://community.esri.com/thread/219641-can-arc-gis-pro-intergrate-with-jetbrains-pycharm.  If you have questions after reading the Esri and Jet Brains documentation, you can ask follow-up questions here.

0 Kudos
VanceRenforth2
Occasional Contributor

Hi Josh,

 In following the steps in the  Configuring Python Interpreter - Help | PyCharm, I get stuck at step 3, "Specify the location of the Conda executable file in the text field, or click Conda executable location and find location in the Conda installation directory." What is the "Conda executable file"? Was this installed with Conda? What format is it in? Where should I expect to find it?

0 Kudos
LukeWebb
Frequent Contributor

It depends where you chose when you installed ArcGIS.

 

For me its this file here:

C:\Program Files\ArcGIS\Pro\bin\Python\python.exe

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Starting with ArcGIS Pro 2.2, there is no python.exe in that path anymore.  The base/bundled python.exe is under the arcgispro-py3 virtual environment:

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If your Pro-bunded Python interpreter is going to be your primary interpreter with PyCharm, I suggest Configuring System Interpreter - Help | PyCharm using the the base/default Pro virtual environment.

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe
0 Kudos
VanceRenforth2
Occasional Contributor

When I go through the above mentioned path and find python.exe, and set that location as the Conda executable file I receive the below failure message.

Non-zero exit code

But I do find this file when I follow the path in windows explorer...

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

As the screenshots in the PyCharm documentation state, you will need admin permissions to the install packages for the system interpreter?  Do you have admin permissions to the folder?

Thinking of the changes Esri made to the bundled Python interperter in Pro, it might be best to just go with per-project virtual environment instead and selecting an existing interperter instead of creating a new one.

From Configuring Virtualenv Environment - Help | PyCharm:

  • If Existing environment is selected:

    1. Specify the required interpreter: use the drop-down list, or click Select an interpreter and find one in your file system.

    2. Select the check-box Make available to all projects, if needed.

  • Click OK to complete the task.

0 Kudos
VanceRenforth2
Occasional Contributor

Any idea how to get around the below stated issue?

0 Kudos