I have a Python module that I need to package as a wheel and publish to a private PyPi. It has a dependency on GDAL>=3.2.2.
Everything needs to run on Linux, Python 3.9.
So I need to find a way to make a wheel from GDAL and store it in my private PyPi.
I tried every possible guide I found but can't make a wheel for Python 3.9 on Linux. The farthest I got was a wheel for 3.8, but when installing it on another machine (or docker) it still needs some other dependencies.
These are my working steps for GDAL 3.2.2 on Python 3.8:
- downloaded the tar.gz from PyPi GDAL 3.2.2
- Extracted it and ran:
sed -i '/gdal_config/c\gdal_config = /usr/bin/gdal-config' setup.cfg
- Then ran:
sudo add-apt-repository ppa:ubuntugis/ppa
sudo apt-get update -y
sudo apt-get install gdal-bin -y
sudo apt-get install libgdal-dev -y
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
- finally ran:
python setup.py bdist_wheel
This created a wheel for Python 3.8 on Linux, but still missing some dependencies... The same process fails for Python 3.9 (appears to be due to some deprecated method) There are precompiled versions for Windows that do work, but I need a solution for Linux.
And lastly, it needs to work in a disconnected network - no Internet. But I can prepare the wheel in a connected environment
Tried everything I could think of...
EDIT
ok, it seems the compilation failed for Python 3.9 because I was missing python3.9-dev. So I also needed:
sudo apt-get install python3.9-dev
So now I can create a wheel for 3.9 which I can install on fresh machines, but when trying to import the module I get:
>>> import osgeo
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/osgeo/__init__.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
File "<frozen importlib._bootstrap>", line 565, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 1173, in create_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
ImportError: libgdal.so.28: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/osgeo/__init__.py", line 32, in <module>
_gdal = swig_import_helper()
File "/usr/local/lib/python3.9/site-packages/osgeo/__init__.py", line 31, in swig_import_helper
return importlib.import_module('_gdal')
File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_gdal'