Unable to import arcpy into MATLAB

5 visualizaciones (últimos 30 días)
Filip
Filip el 16 de Abr. de 2024
Comentada: Jeff Burkey el 1 de Abr. de 2025
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.

Respuestas (1)

Karanjot
Karanjot el 22 de Abr. de 2024
Editada: Karanjot el 22 de Abr. de 2024
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 comentario
Jeff Burkey
Jeff Burkey el 1 de Abr. de 2025
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

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by