Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Last active March 8, 2023 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdsumner/526af876cfddaa5ff245ab376b3cec84 to your computer and use it in GitHub Desktop.
Save mdsumner/526af876cfddaa5ff245ab376b3cec84 to your computer and use it in GitHub Desktop.

Below is a bash session, in a docker container running GDAL docker/ubuntu-small. In the container in 'builder' mode I've run

cmake .. -DCMAKE_BUILD_TYPE=Debug
sudo cmake --build .  --target install 

I start python3, which is 3.10.6 - and GDAL has placed the osgeo libs into '/usr/local/lib/python3/dist-packages', but python is only looking in '/usr/local/lib/python3.10/dist-packages'

Is there a config step with cmake, or a subsequent step with python config that I should be doing? (do I just symlink the libs??)

root@53837d4fa20e:/gdal-source/build2# python3
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from osgeo import gdal
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'osgeo'
>>>
[3]+  Stopped                 python3


ls /usr/lib/python3/dist-packages/
_distutils_hack  numpy  numpy-1.21.5.egg-info  pkg_resources  setuptools  setuptools-59.6.0.egg-info

ls /usr/local/lib/python3/dist-packages/
GDAL-3.7.0.egg-info  osgeo  osgeo_utils


python3
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/usr/local/lib/python3.10/dist-packages', '/usr/lib/python3/dist-packages']
>>>

Details above were posted to back up this question on gdal-dev: https://lists.osgeo.org/pipermail/gdal-dev/2023-March/057000.html

@mdsumner
Copy link
Author

mdsumner commented Mar 8, 2023

The answer is to not use the implicit value for CMAKE_INSTALL_PREFIX which is /usr/local, set it to /usr:

cmake .. -DCMAKE_INSTALL_PREFIX=/usr 
cmake --build . --parallel 31  --target install 

thanks Even Rouault https://lists.osgeo.org/pipermail/gdal-dev/2023-March/057001.html

all working now without extra cruft. For reference we can do the implicit one cmake .. ; cmake --build . etc by following up with

sudo ldconfig ## because /usr/local/lib/python3/dist-packages/ has just been created by GDAL and didn't exist before
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3/dist-packages

but then you have extra stuff going on so let's avoid it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment