55
Configuring IDL Python Bridge with venv Virtual Python environment on Windows
If you have difficulties to configure IDL Python bridge with a virtual venv Python environment, it may be due to the fact that such virtual environments are missing almost all of the required Libs, site-packages, and DLLs. They all come from the parent environment. The IDL Python bridge does not know that it is a virtual environment and assumes that everything is located within the Python venv directory.
Notes: if you are using Anaconda Virtual Environments, this article is not relevant. It is only relevant for Venv Virtual Environments.
Below is a link about how to create and activate a venv virtual Python environment on Windows:
https://mothergeo-py.readthedocs.io/en/latest/development/how-to/venv-win.html
Various errors may be encountered while using the IDL Python bridge with such venv virtual Python environment on Windows:
- Error about missing the numpy library when calling IDL from Python
(ModuleNotFoundError: No module named 'numpy'
- Error about missing the Python bridge DLL when calling Python from IDL
% PYTHON::RUN: DLM_LOAD: Error loading sharable executable.
Symbol: IDL_Load, File = C:\Program Files\NV5\IDL90\bin\bin.x86_64\idl_python311.dll
The specified module could not be found.
- Error about Python configuration failure when calling Python from IDL
% Loaded DLM: PYTHON311.
% PYTHON_INIT: C:\Users\Public\Python_venv\env3112.
% PYTHON::RUN: PYTHON_INIT: Py_InitializeFromConfig failed..
Those errors are usually related to missing paths in the PATH and/or PYTHONPATH environment variables. The following steps show how to fix such errors.
In the example below
- the virtual venv Python environment is located in C:\_BERANGERE\vmpython
- the parent Python environment is located in C:\Users\berangere\AppData\Local\Programs\Python\Python311\
In case you do not know where the parent Python directory resides, you can use the commands below to determine its location from the Python venv environment
C:\_BERANGERE\venvpython>.\venv\Scripts\activate
(venv) C:\_BERANGERE\venvpython>python
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.base_prefix
'C:\\Users\\berangere\\AppData\\Local\\Programs\\Python\\Python311'
You now need to add the below directories to your PATH environment variable
- Path to the Scripts directory of your Python venv environment: C:\_BERANGERE\vmpython\venv\Scripts;
- Paths to these two parent Python installation directories:
C:\Users\berangere\AppData\Local\Programs\Python\Python311\Scripts\;
C:\Users\berangere\AppData\Local\Programs\Python\Python311\;
- Path to the IDL directory
C:\Program Files\NV5\IDL91\bin\bin.x86_64\;
You also need to define the PYTHONPATH environment variable including the following parent Python installation directories:
C:\Users\berangere\AppData\Local\Programs\Python\Python311\DLLs;
C:\Users\berangere\AppData\Local\Programs\Python\Python311\Lib;
C:\Users\berangere\AppData\Local\Programs\Python\Python311\Lib\site-packages;
Afterwards you can use the Python-to-IDL and the IDL-to-Python bridges with your virtual venv Python environment
- Activate your venv virtual Python environment in the terminal session
C:\_BERANGERE\venvpython>.\venv\Scripts\activate
- Launch Python and add the IDL bridges path to system PATH
(venv) C:\_BERANGERE\venvpython>python
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> sys.path.append('C:\\Program files\\nv5\\idl91\\lib\\bridges')
>>> from idlpy import *
IDL 9.1.0 (Win32 x86_64 m64).
(c) 2024, NV5 Geospatial Solutions, Inc.
- Test the Python to IDL bridge
>>> p=IDL.plot(TEST=1)
% Loaded DLM: SVG.
% Loaded DLM: LAPACK.
>>> exit()
(venv) C:\_BERANGERE\venvpython>idl
IDL 9.1.0 (Win32 x86_64 m64).
(c) 2024, NV5 Geospatial Solutions, Inc.
Licensed for use by: NV5 Geospatial Internal Use Only
License:xxxxxx-internal
- Test the IDL to Python bridge, bridging to your virtual Python venv environment
IDL> >>>2+2
% Loaded DLM: PYTHON311.
% PYTHON_INIT: C:\_BERANGERE\venvpython\venv.
4
IDL> >>>
>>> import numpy as np
>>> arr=np.random.rand(100)
>>> print(arr.mean())
0.4763549858054967
>>>
---------------------------------------------
created by BC on 2/19/2025
reviewed by BC (US) on 2/27/2025