IDL and ENVI ship with a pre-configured and full-featured Python installation. This embedded Python contains numerous packages including numpy and pandas. In addition, the PyUtils class makes it easy to install additional packages for this Python environment. To use the embedded Python, simply issue a Python command to load this Python in your current IDL session:

IDL> np = Python.Import("numpy")
% Python is embedded version 3.xx.
% Loaded DLM: PYTHON3xx.
% PYTHON_INIT: C:\Program Files\NV5\IDL92\bin\bin.x86_64\idl-python3xx.

To add a new package to the embedded Python:

IDL> PyUtils.PipInstall, 'beautifulsoup4'
Package beautifulsoup4 successfully installed in C:\Users\myusername\.idl\idl\python_idlx_x.
IDL> bs4 = Python.Import('bs4')
IDL> myhtml = '<html><title>IDL is great</title></html>'
IDL> soup = bs4.BeautifulSoup(myhtml, 'html.parser')
IDL> print, soup.title.string
IDL is great

If you are using the embedded Python, you should not need to do any additional configuration or setup. See PyUtils for additional commands.

Custom Python Installations


Instead of using the embedded Python that ships with IDL, you can use your own Python installation.

First, install a working copy of Python, plus the numpy library (version 2.x.x). One method to install Python is to install a pre-configured installation such as Anaconda. For example, if you download Anaconda, then from a shell you should be able to execute:

conda create --name py313 python=3.13
conda activate py310
conda install numpy==1.26.4

The next step is to configure your system so that IDL and Python can find each other.

Windows


Ensure that your Python executable is on the system PATH environment variable. IDL will use the first Python executable that it finds. If you use a virtual environment such as Anaconda from a Windows shell, then the correct Python should automatically be on your path after you activate it. If you are using your own Python installation then you may need to add Python to your system path. Here are some possible scenarios:

IDL Command Line or Workbench - You will need to add the Python executable to your Windows system PATH environment variable.

Anaconda Prompt or Git Bash with IDL Command Line - Once you do the conda activate command, you should not need to modify the PATH. IDL should automatically find the correct Python.

Windows Powershell with IDL Command Line - You will need to add the Python executable to your Windows system PATH environment variable.

Starting your Python

To start your Python within IDL, you should use the PyUtils.Load command:

IDL> PyUtils.Load, 'python313'  ; start your flavor of Python

Linux


Ensure that your Python executable is on the system PATH environment variable. IDL will use the first Python executable that it finds. If you use a virtual environment such as Anaconda, then the correct Python should automatically be on your path after you activate it. If you are using your own Python installation then you may need to add Python to your system path.

In addition, you will need to add the Python lib directory to the LD_LIBRARY_PATH environment variable.

For example, if you are using Anaconda, then you should be able to execute:

conda activate py310
setenv LD_LIBRARY_PATH ${CONDA_PREFIX}/lib:${LD_LIBRARY_PATH}
idl
IDL> PyUtils.Load, 'python313'  ; start your flavor of Python
IDL> >>>2+2

macOS


Ensure that your Python executable is on the system PATH environment variable. IDL will use the first Python executable that it finds. If you use a virtual environment such as Anaconda, then the correct Python should automatically be on your path after you activate it. If you are using your own Python installation then you may need to add Python to your system path.

On macOS, the final step is to run the setup.py install script for the IDL Python bridge. Using the Mac terminal shell, navigate to the <IDL_DIR>/lib/bridges directory and then run the script.

For example:

cd /Applications/<install dir>/idlxx/lib/bridges
python setup.py
idl
IDL> PyUtils.Load, 'python313'  ; start your flavor of Python

This script will install a symbolic link in your IDL bin directory that points to the correct Python library.

Note: Be sure that you run setup.py using the same Python that you wish to use for the IDL Python bridge.

Note: Depending on the installation location and who installed IDL, you might need to run the setup.py script as a "super-user" (sudo). If the script fails with an error about permissions, either re-run the script using these elevated privileges or contact your System Administrator and have them run the script.

Starting Your Python


If you are using the embedded Python that ships with IDL, you should not need to do anything other than start executing Python commands.

If you are using your own Python, you need to call PyUtils.Load to pick the appropriate Python bridge library. For example:

IDL> PyUtils.Load, 'python313'  ; your Python is 3.13

or...

IDL> PyUtils.Load, 'python312'  ; your Python is 3.12

or...

IDL> PyUtils.Load, 'python311'  ; your Python is 3.11

You can then execute regular Python commands for the rest of your IDL session. If you always want to use this Python, you can just put the PyUtils.Load into the top of your IDL program, or even in the IDL startup file.

Testing Your Installation


Once you have completed the installation, you should be able to start IDL and execute Python commands:

IDL> PyUtils.Load, 'python313'  ; start your flavor of Python
IDL> >>>2+2
% Loaded DLM: PYTHON3xx.
4

If you receive any errors, make sure that the correct Python is on your system PATH.

On Linux, if you receive an error about loading the library, make sure that the Python lib directory has been added to LD_LIBRARY_PATH.

On macOS, if you receive an error about loading the library, make sure that you have run the setup.py script using the correct Python.

Note: On Linux or macOS, if you receive any errors about INTEL MKL, this is due to a conflict between IDL's mkl library and Python's mkl. To resolve the problem, issue the following commands from a terminal:

conda uninstall mkl
conda install nomkl
conda install numpy==1.26.4

See Also


Python to IDL Bridge Installation, Using the IDL to Python Bridge, PyUtils Class