2026
How to use several Python versions in IDL on Linux
There is not currently a direct way to call various Python versions from IDL on Linux, without restarting a fresh IDL session (as of IDL 8.8.2).
The main issue is that LD_LIBRARY_PATH cannot be modified on the fly in IDL : IDL needs to be restarted to change to LD_LIBRARY_PATH. Indeed this variable is only read at IDL startup.
This article proposes a workaround using the IDL_IDLbridge. It is based on an example developed on Linux Ubuntu 22.04, with Anaconda3 Python distribution and Python 3.8 and 3.10 environments.
Example
- Activate Python 3.1O environment from Ananconda
conda activate python310
- Set the LD_LIBRARY_PATH to point to Python 3.10 environment from IDL
export LD_LIBRARY_PATH=/home/support-u22/anaconda3/envs/python310/lib
Note the PATH environment variable already includes the path to /anaconda3/envs/python310/bin: it is set automatically when activating the Python 3.10 environment at previous step.
- Start IDL
(base) support-u22@support-VirtualBox:~$ idl
IDL 8.8.2 (linux x86_64 m64).
(c) 2022, L3Harris Geospatial Solutions, Inc.
Licensed for use by: idl_user
License: 1234-linux
- Import Python from IDL and confirm version 3.10 is started
IDL> sys1=Python.Import('sys')
% Loaded DLM: PYTHON310.
IDL> print,sys1.version
3.10.4 (main, Mar 31 2022, 08:50:39) [GCC 7.5.0]
- Still from the same IDL session change the LD_LIBRARY_PATH variable to point to Python 3.8 instead of 3.10
setenv,'LD_LIBRARY_PATH=/home/support-u22/anaconda3/envs/python38/lib'
- Then modify the PATH variable to point to Python 3.8 instead of 3.10
IDL> path=getenv('PATH')
IDL> new_path=path.replace('python310','python38')
IDL>setenv,'PATH='+new_path
- Create an IDL_IDLBridge object
IDL> obj=obj_new('IDL_IDLbridge')
% Loaded DLM: IDL_IDLBRIDGE.
IDL> help,obj
OBJ OBJREF = <ObjHeapVar11(IDL_IDLBRIDGE)>
- Check that PATH and LD_LIBRARY_PATH in the IDL_IDLbrdige session to confirm they are now both pointing to Python 3.8 instead of 3.10
IDL> obj.execute,"ldpath=getenv('LD_LIBRARY_PATH')"
IDL> obj.execute,"path=getenv('PATH')"
IDL> print,obj.getvar('path')
/usr/local/harris/envi56/idl88/bin:/home/support-u22/anaconda3/envs/python38/bin:/home/support-u22/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin
IDL> print,obj.getvar('ldpath')
/usr/local/harris/envi56/idl88/bin/bin.linux.x86_64:/home/support-u22/anaconda3/envs/python38/lib
- Execute Python in the IDL_IDL_bridge child session
IDL> obj.execute,"sys2=Python.Import('sys')"
- Confirm Python 3.8 version is started in IDL_IDLbridge session
IDL> obj.execute,"version2=sys2.version"
IDL> print,obj.getvar('version2')
3.8.13 (default, Mar 28 2022, 11:46:24)
[GCC 7.5.0]
---------------------------------------
created by BC on 8/5/2022
reviewed by BC(US) on 8/8/22