Can't import arcpy in PyCharm

7281
8
Jump to solution
01-13-2021 05:24 PM
AllenDailey1
Occasional Contributor III

I am running into an error when running a script that tries to import arcpy, in PyCharm, using Pro rather than ArcMap, on a virtual server machine that my organization wants to use to store and run scripts in our enterprise environment.  I am trying to get the server set up for this.  I have used arcpy in Pycharm on my own PC just fine; I do not know what the problem is with it on the server.  I have tried all kinds of possible fixes.  Can anyone help?

I already uninstalled and reinstalled both Pro and PyCharm, and I have deleted tons of PyCharm projects and created new ones with different settings.  I get the same error no matter what I try.

Pro version: 2.7

Python: 3.7

Here is the error:

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\numpy\__init__.py:138: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
  from . import _distributor_init
Traceback (most recent call last):
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\numpy\core\__init__.py", line 22, in <module>
    from . import multiarray
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
    from . import overrides
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/Scripts/pythonProject/test2.py", line 3, in <module>
    import arcpy
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\__init__.py", line 21, in <module>
    import numpy
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import core
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\numpy\core\__init__.py", line 48, in <module>
    raise ImportError(msg)
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.7 from "D:\Scripts\pythonProject\Scripts\python.exe"
  * The NumPy version is: "1.19.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: DLL load failed: The specified module could not be found.

I've already clicked and Googled everything I have found or thought of, and I've read lots of stuff about Pro and PyCharm from Esri and on Geonet and Stack Exchange, etc.  But none of the solutions work for me. 

Here is my project interpreter setting (I have tried various other settings):

AllenDailey1_0-1610586891057.png

I did try making it a conda environment a couple times and pointing to a file within ArcGIS Pro that had conda in the name.  Note that I do not know what conda is or how it may be relevant or not in this situation.

Here is my sys.path:

D:\Scripts\pythonProject\Scripts\python.exe D:/Scripts/pythonProject/test2.py
D:\Scripts\pythonProject
C:\Program Files\ArcGIS\Pro\Resources\ArcPy
D:\Scripts\pythonProject
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python37.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
D:\Scripts\pythonProject\lib\site-packages
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\ArcToolbox\Scripts
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\future-0.18.2-py3.7.egg
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pytz-2020.1-py3.7.egg
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pywin32_ctypes-0.2.0-py3.7.egg
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pywin32security
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\sympy-1.5.1-py3.7.egg

 

The error has something to do with numpy, and with mkl-service, but I have both of those:

AllenDailey1_1-1610587282015.png

Any help would be much appreciated, because I am 100% stuck now, after banging my head against the wall with this for several days.  Thank you!!

0 Kudos
1 Solution

Accepted Solutions
AllenDailey1
Occasional Contributor III

Well, I finally fixed it.  I think it came down to correcting my Pro license.  I feel kind of dumb for not doing that to begin with, but it is also frustrating that there was no hint anywhere along the line that it was an issue.

I installed ArcMap on the server to see if the ArcMap version of arcpy would work any better than the Pro version.  When I did the installation, ArcMap forced me to look at the license manager and deal with it, and I realized that I didn't recall doing anything with that when I installed Pro, even though I did log into Pro with my AGOL account just fine.  I went into the licensing settings in Pro, saw that they were incorrect, and I corrected them.

Then I went back to PyCharm.  I went to edit the settings for the project interpreter.  This time, it had "system environment" as an option, along with conda or virtual environment.  This seemed like a good sign, because I had seen instructions to use "system environment" in online resources, but it was never available as an option to me.  So I picked "system environment" and the same Python path I had tried before, 

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

I chose to "inherit global site packages," as I already had done in my previous attempts.  And, this time it worked!  My script successfully imported arcpy and ran!

So it was all just a licensing issue.  Ugh.  I really wish there had been an error message somewhere along the way, either when I attempted to import arcpy, or when I opened/used Pro itself, that my license wasn't valid.

View solution in original post

8 Replies
DanPatterson
MVP Esteemed Contributor

sounds like the specs for the server don't match what is expected for the version of python/numpy.

It is working on your local machine since python is installed on a conventional windows machine.  Python and hence numpy is installed in the path that ArcGIS Pro is installed.

C:\arc_pro                                                 install folder

C:\arc_pro\bin\Python                            python.exe executable

C:\arc_pro\bin\Python\Scripts               conda launch and environment switching bat files

C:\arc_pro\bin\Python\envs\arcgispro-py3     The Pro base/main environment

C:\arc_pro\bin\Python\envs\arcgispro-py3\Lib\site-packages    site packages (eg numpy, pandas, scipy etc)

What does it look on your machine? and is their a real need to not have local installs?

I use Spyder which installed within the site packages so it is easy for it to find anything.  You will have to find a pycharmer for your specifics, but I presume it needs to be installed relative to the location of Pro.


... sort of retired...
0 Kudos
AllenDailey1
Occasional Contributor III

Dan, thank you for your reply!

What do you mean by local installs?

Do you have any ideas as to what specs of the server I should check to see if it is compatible with numpy?

Pro is installed on the C drive of the server, and it has all the folders that you listed.  In PyCharm, I am attempting to use as my interpreter (this is part of Pro, on the server's C drive):

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

 My PyCharm project (the .py script I'm trying to run) is saved on the D drive of the same server (so Pro is on the C drive and my python file/project is on the D drive).  PyCharm requires that a virtual environment be set up for running .py files, so this virtual environment is on the D drive.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Outside of PyCharm, if you open the Pro-created Python stand-alone window and import arcpy, does it give the same error?

0 Kudos
AllenDailey1
Occasional Contributor III

Thanks for your idea!  I'm not sure what you mean by the Pro-created Python stand-alone window.  The Python window within Pro?

Sorry for my ignorance; I'm still a beginner.

0 Kudos
DanPatterson
MVP Esteemed Contributor

Allen, I work in a standalone Pro environment.  Spyder doesn't require a virtual environment so I can't comment on whether there are issues there.

If it is a windows machine then I would stick with numpy 1.19.2 which distributes with Pro. 

There is no need to upgrade beyond this point at this time.  numpy 1.20 (coming soon) will no longer support python 3.6 and there are some issues with newer apple chips that are being ironed out.

 


... sort of retired...
0 Kudos
AllenDailey1
Occasional Contributor III

Well, I finally fixed it.  I think it came down to correcting my Pro license.  I feel kind of dumb for not doing that to begin with, but it is also frustrating that there was no hint anywhere along the line that it was an issue.

I installed ArcMap on the server to see if the ArcMap version of arcpy would work any better than the Pro version.  When I did the installation, ArcMap forced me to look at the license manager and deal with it, and I realized that I didn't recall doing anything with that when I installed Pro, even though I did log into Pro with my AGOL account just fine.  I went into the licensing settings in Pro, saw that they were incorrect, and I corrected them.

Then I went back to PyCharm.  I went to edit the settings for the project interpreter.  This time, it had "system environment" as an option, along with conda or virtual environment.  This seemed like a good sign, because I had seen instructions to use "system environment" in online resources, but it was never available as an option to me.  So I picked "system environment" and the same Python path I had tried before, 

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

I chose to "inherit global site packages," as I already had done in my previous attempts.  And, this time it worked!  My script successfully imported arcpy and ran!

So it was all just a licensing issue.  Ugh.  I really wish there had been an error message somewhere along the way, either when I attempted to import arcpy, or when I opened/used Pro itself, that my license wasn't valid.

Jean-CédricDelposen
New Contributor

What type of license do you use ? (and extension ?)

0 Kudos
AllenDailey1
Occasional Contributor III

To answer your question, I use a concurrent use license, Standard license, with no special extensions unless I need them for a specific task.  My problem (described in the original post) was because I had not connected to my organization's licensing in ArcGIS Pro.  Whoops.  So I was attempting to use Pro without any license.

0 Kudos