Unable to import arcpy into MATLAB

조회 수: 5 (최근 30일)
Filip
Filip 2024년 4월 16일
댓글: Jeff Burkey 2025년 4월 1일
Using MATLAB 2023b, trying to run Python commands, mainly ArcGIS Pro related stuff via arcpy library. pyenv is set to use the correct Python installation (the one containing arcpy). Arcpy in Python works fine while I´m unable to import it into MATLAB. The import error seems to be more arcpy related.
Arcpy works fine on my computer. Also tried restarting both the computer and ArcGIS Pro. Even reinstalled ArcGIS Pro. Made an arcpy clone, unsuccessfully tried to update all packages it contains (via Package manager in ArcGIS Pro options menu). I get the same problem for both original arcpy and the clone.
It crashes while importing it. This is weird because I can import and use math library, which is installed in the Python intepreter by default. I use "a = py.importlib.import_module('arcpy');" to import it.
The error I get:
Python Error: ImportError: DLL load failed while importing _arcgisscripting: <'listed procedure not found' - kind of message in my system´s language>.
Will be grateful for any help!
*UPDATE*
1) Adding arcpy-Python interpreter into PATH as suggested here didn´t help.
2) Tested importing arcpy into MATLAB on different PC, setting pyenv to arcpy interpreter worked, so did working with other libraries installed in it (e. g. math, mentioned in 2st paragraph). Got exactly the same error.

답변 (1개)

Karanjot
Karanjot 2024년 4월 22일
편집: Karanjot 2024년 4월 22일
Hey Filip,
Kindly share details about your python installation, and also confirm if you are using the Anaconda distribution for python. The above error is common with Anaconda distribution.
This is because Anaconda maps the DLLs in a non-standard spot and adds them to the path when you start Anaconda's Prompts or Navigators. The math library uses python directly. To be fast, libraries uses compiled C-code, hence those extra DLLs.
In case you are using Anaconda, Here's a workaround:
  1. Launch Anaconda Prompt or Anaconda Powershell Prompt
  2. Type matlab at the prompt. Matlab will launch with extra environment variables configured by Anaconda's startup.
  3. Test in MATLAB.
Otherwise, If you are using any Python version > 3.8 with Windows, DLLs are only loaded from trusted locations as suggested in Python documentation: https://docs.python.org/3/whatsnew/3.8.html#ctypes
This can be fixed by adding the dll path in python using:
os.add_dll_directory("PATH_TO_DLL")
In case you still encounter the error, I recommend going through below documentation to ensure that your system is configured correctly:
I hope this helps!
  댓글 수: 1
Jeff Burkey
Jeff Burkey 2025년 4월 1일
To Karanjot (or other).
I'm getting the EXACT same error. I haved added environment paths. When writing python, I'm writing it using the Arcpro python environment. Searching for help on this, maybe it's a licensing issue? I have a licensed version of ArcPro 3.3.2 installed on my desktop. I think before importing arcpy, I need to activiate the ESRI license. It's unclear to me how to do that from matlab. Using arcpy from Anaconda is not really a good idea, because my understanding is ARCPY is not kept up to date by ESRI in that channel.
I really could use some help on this.
Example of the file path below and using pyenv:
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3
So I'm not using anaconda. The python version installed with my Arcpro is 3.11.
PythonEnvironment with properties:
Version: "3.11"
Executable: "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe"
Library: "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python311.dll"
Home: "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3"
Status: NotLoaded
ExecutionMode: InProcess

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by