Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional python packaging documentation, version correction #9405

Merged
merged 3 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions swig/python/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,54 @@ Once you have Anaconda or Miniconda installed, you should be able to install GDA

``conda install -c conda-forge gdal``

Unix
~~~~

The GDAL Python bindings requires setuptools.

pip
~~~

GDAL can be installed from the `Python Package Index <https://pypi.org/project/GDAL>`__:
GDAL can be installed from the `Python Package Index <https://pypi.org/project/GDAL>`__.
Due to the complex nature of GDAL and its components, different bindings may require additional packages installation steps.
The base GDAL package contains support for OGR, OSR, and GDAL vectors:

::

pip install gdal

It will be necessary to have libgdal and its development headers installed
if pip is expected to do a source build because no wheel is available
for your specified platform and Python version.

To install with numpy support, you need to require the optional numpy component:
In order to enable raster support, libgdal and its development headers must be installed as well as the Python packages numpy, setuptools, and wheel.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"raster support". Well GDAL without numpy does support raster, it is just that it is not very convenient if you need to inspect array values, but you can for example script raster conversion with gdal.Translate() without requiring numpy. Maybe use "numpy-based raster support" ? (here and below). The sentence "The base GDAL package contains support for OGR, OSR, and GDAL vectors:" above should also be reworked, as it gives the impression that there's no raster support at all

To install the Python dependencies and build raster support:


::

pip install numpy>1.0.0 wheel setuptools>=67
pip install gdal[numpy]=="$(gdal-config --version).*"


Users can verify that reaster support has been installed with:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Users can verify that reaster support has been installed with:
Users can verify that raster support has been installed with:


::

python3 -c 'from osgeo import gdal_array'


If this command raises an ImportError, raster support has not been properly installed:

::

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.12/dist-packages/osgeo/gdal_array.py", line 10, in <module>
from . import _gdal_array
ImportError: cannot import name '_gdal_array' from 'osgeo' (/usr/local/lib/python3.12/dist-packages/osgeo/__init__.py)

pip install gdal[numpy]

To install the version of the Python bindings matching your native GDAL library:
This is most often due to pip reusing a cached GDAL installation.
Verify that the necessary dependencies have been installed and then run the following to force a clean build:

::
pip install --no-cache --force-reinstall gdal[numpy]=="$(gdal-config --version).*"


pip install gdal=="$(gdal-config --version).*"

Building as part of the GDAL library source tree
------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion swig/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=61.0.0", "oldest-supported-numpy", "wheel"]
requires = ["setuptools>=67.0.0", "oldest-supported-numpy", "wheel"]
build-backend = "setuptools.build_meta"

[project]
Expand Down
Loading