I have a package that is giving me trouble (netCDF4). I found out that if I download and build the source code myself, it works fine.
There are two ways to install this package from source. For the examples below, the source code is at ~/netcdf
.
use
pip install ~/netcdf
, it will build and run just fine.use
python3 -m build
from the~/netcdf
directory and then install the wheel/tar.gz file from thedist
subfolder.
The former works fine. But the latter yields a package that seems to be incomplete.
A good test for it is running `python3 -c "from netCDF4 import Dataset". With the pip-installed source code that works fine. With my own build, that results in an error:
ImportError: cannot import name 'Dataset' from 'netCDF4' (unknown location)
What is the difference between wheels generated by python3 -m build
and pip install
? Note that the package must be compiled (it is not pure python).
NOTE: I don't need help with netCDF4. I want to understand why both builds yield different results.
To reproduce:
wget https://github.com/Unidata/netcdf4-python/archive/refs/tags/v1.6.2.tar.gz
tar -xvzf v1.6.2.tar.gz
cd netcdf4-python-1.6.2
python3 -m build # this creates its own, clean virtual env for building (depends on package **build**)
python3 -m venv ./env && source env/bin/activate
pip3 install dist/netCDF4-1.6.2-cp310-cp310-linux_x86_64.whl
python3 -c "from netCDF4 import Dataset" # I get an error
deactivate && rm -rf ./env
python3 -m venv ./env && source env/bin/activate
pip install .
python3 -c "from netCDF4 import Dataset"
During the python3 -m build
routine, I also get some compiler warnings which I don't see using the pip installation, but I assume these are suppressed as I doubt that pip magically corrects these C impurities.