matplotlib / basemap

Plot on map projections (with coastlines and political boundaries) using matplotlib

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Import fails due to "is_scalar" error (fresh installation)

paullb514 opened this issue · comments

Python verison 3.6.4
mathplotlib verison 3.0.1

Simpletest.py test script fails with the following error after compiling from source as per the instructions:

$ python3 simpletest.py
Traceback (most recent call last):
File "simpletest.py", line 1, in
from mpl_toolkits.basemap import Basemap
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mpl_toolkits/basemap/init.py", line 17, in
from matplotlib.cbook import is_scalar, dedent
ImportError: cannot import name 'is_scalar'

It looks like you have an older version of basemap. This has already been fixed and is in the released version v1.2.0.

Some notes: basemap is considered deprecated in favor of the cartopy package. Please learn cartopy instead. Second, the preferred method of installing basemap (or cartopy) is through conda-forge due to its complex build process and dependencies.

I downloaded the latest version of the website today so if that's the case the page needs ot be updated.

I did ultimately get it going using conda. I will looking into Cartopy as well so thanks for that!

Had the same issue, resolved by upgrading basemap:
sudo pip install -U git+https://github.com/matplotlib/basemap.git

I just ran into this as well, even though I was using the latest version on PyPI (which is 1.0.7), see https://pypi.org/project/basemap/#history .

Any reason why the latest basemap releases are not published on PyPI?

I'm unable to resolve this issue, even though I'm using the version v1.2.0. I'm using Ubuntu 18.04, python 3.6.
During the execution of configure, I encountered undefined isnan macro error, which I resolved by replacing line 24 in platform.h file with #define HAVE_ISNAN 1.

Wher do you find the platform.h?

I managed to solve this "is_scalar" problem by doing what suggested by @samfway, but when running from mpl_toolkits.basemap import Basemap I get the following:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.6/dist-packages/mpl_toolkits/basemap/__init__.py", line 48, in <module> import _geoslib ImportError: libgeos-3.3.3.so: cannot open shared object file: No such file or directory

Any clue on how to solve this?

@goyal-vi The error is due to your environment being incompatible (too new) with the old GEOS version. A workaround is to issue the following command before running configure,

export CXX="g++ -std=c++98"

@davide-p The error message simply states that the GEOS library cannot be found. Assuming that you have already compiled it as per the instructions, i.e. with GEOS_DIR=/usr/local, it should be sufficient to modify your LD_LIBRARY_PATH as follows,

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

The source link is still pointing to 1.1.0 on the https://matplotlib.org/basemap/users/installing.html page

Installing matplotlib in 2.2.0 will work
conda install matploblib=2.2.0

Maybe I must have missed something? However, I've downloaded Anaconda and setup a virtual python environment specifically to install matplotlib (I tried both versions; 3.1.1 and 2.2.0) as well as basemap v1.2.0 and I am still getting the "cannot import is_scalar" error.
I guess I'll start reading the cartopy docs?

Referencing the link comments above (i.e. WeatherGod and dbpodrasky), the download link [https://matplotlib.org/basemap/users/download.html] is still pointing to v1.1.0. That link for basemap is still causing installation issues. samfway's solution above works if you end up on this page.

This worked for me:

pip install -U matplotlib==3.2
conda install -c conda-forge basemap