Forums

Importing basemap library

Hi All, i am working on an app which would make use of basemap library. Basemap tends to be tricky to install therefore i was happy to find out that it comes a part of preinstalled packages on pythonanywhere : https://www.pythonanywhere.com/forums/topic/3527/ For some reason i am not able to import mpl_toolkits.basemap though , getting the error : ModuleNotFoundError: No module named 'mpl_toolkits.basemap' Is there any additional step i would need to take to make this module available?

Thanks Bart

could it be a basemap version issue? what version of python, basemap, and matplotlib are you using?

Hi Conrad, thanks for looking into this.

I'm using python 3.7, matplotlib - no idea , i'm just importing the pre-installed version with : import matplotlib.pyplot as plt , which that doesn't raise any errors.
Based on https://www.pythonanywhere.com/forums/topic/3527/ I assumed I could use basemap without any additional installation just like flask, pandas etc

aha, if you check out this, you will see that we have basemap installed up to python3.6 for your particular system image. so if you want to use python3.7, you would have to install basemap yourself.

I think that it is possible that when we were creating the particular system image that you were on, basemap was not compiling successfully on python3.7- and that's why we dropped it. It is possible that basemap now supports up to python3.7/3.8, but you will have to double check yourself.

Thanks for the super-useful tool (batteries included) . I misled you though, i am my app is using python 3.6 and i when i open a 3.6 console i am able to import basemap. I am not able to do that from the flask.app , could it be because i have it on the virtual environment - i.e. would have to install basemap separately there? If that's the case could you share a bullet-proof command to install this package ? From what i've read it's notoriously tricky to install all the dependencies. many thanks in advance

If you're using a virtualenv, then that virtualenv will need to have basemap installed. You can use the --system-site-packages argument when you're creating a virtualenv and then it will be able to "see" packages installed at the system level, but that may have strange compatibility issues depending on what packages you install into the virtualenv.

We stopped installing basemap because it is being deprecated in favour of CartoPy, so we do not have instructions for installing it.