matplotlib / basemap

Plot on map projections (with coastlines and political boundaries) using matplotlib
MIT License
779 stars 392 forks source link

building from source creates a __init__.py in mpl_toolkits namespace #456

Closed lee218llnl closed 2 years ago

lee218llnl commented 5 years ago

When I install the 1.2.0 release from source (i.e., python setup.py install), I am unable to import mpl_toolkits.basemap in the resulting installation:

% python -c 'from mpl_toolkits.basemap import Basemap' Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'mpl_toolkits.basemap'

I believe this is because of the lib/python3.7/site-packages/basemap-1.2.0-py3.7-linux-x86_64.egg/mpl_toolkits/init.py file. From what I read in https://packaging.python.org/guides/packaging-namespace-packages/, it sounds like the presence of an init.py file in the namespace directory is the cause of this failure:

It is extremely important that every distribution that uses the namespace package omits the init.py or uses a pkgutil-style init.py. If any distribution does not, it will cause the namespace logic to fail and the other sub-packages will not be importable.

Removing this init.py file appears to fix the import problem for me.

molinav commented 2 years ago

We have recently released basemap version 1.3.0, which includes several changes related to the library packaging. From this version, precompiled wheels are available in PyPI (including your case with Python 3.7 under GNU/Linux x86_64), so you can simply install basemap using pip:

python -m pip install basemap

which will install basemap-data in addition. If you also need the high-resolution data files, you need to install basemap-data-hires manually:

python -m pip install basemap-data-hires

Hope this helps. If the problem persists, feel free to write here or open a new issue.