Monday, June 13, 2022

[Solved] Install matplotlib / basemap in macOS

I have been trying to import the basemap module in my python script using "
from mpl_toolkits.basemap import Basemap" but with no luck! I ran into issues while installing basemap with pip. Excerpt from the error:

  Installing build dependencies ... error

  errorsubprocess-exited-with-error

  

  × pip subprocess to install build dependencies did not run successfully.

   exit code: 1

  ╰─> [552 lines of output]

      Ignoring numpy: markers 'python_version >= "3.10"' don't match your environment

      Ignoring numpy: markers 'python_version == "2.6" or (python_version >= "3.2" and python_version <= "3.3")' don't match your environment

      Ignoring cython: markers 'python_version == "3.2"' don't match your environment

...

...

        note: This error originates from a subprocess, and is likely not a problem with pip.

      error: legacy-install-failure

      

      × Encountered error while trying to install package.

      ╰─> numpy

      

      note: This is an issue with the package mentioned above, not pip.

      hint: See above for output from the failure.

      WARNING: There was an error checking the latest version of pip.

      [end of output]

  

  note: This error originates from a subprocess, and is likely not a problem with pip.

errorsubprocess-exited-with-error


× pip subprocess to install build dependencies did not run successfully.

 exit code: 1

╰─> See above for output.


note: This error originates from a subprocess, and is likely not a problem with pip.

WARNING: There was an error checking the latest version of pip.



So I did a little digging and searched for necessary packages to compile and install basemap on macOS from the source. I have Python 3.9 and macOS 12.4. Here are the steps that worked for me:
  • brew install matplotplusplus
  • brew install numpy
  • brew install proj
  • brew install geos
  • export GEOS_DIR="/usr/local/Cellar/geos/3.10.3/"
  • pip3 install cython
  • pip3 install numpy
  • git clone https://github.com/matplotlib/basemap.git
  • cd basemap
  • cd packages
  • cd basemap
  • python3 setup.py install
  • cd ..
  • cd basemap_data
  • python3 setup.py install
  • cd ..
  • cd basemap_data_hires
  • python3 setup.py install
  • cd ..
  • cp -R basemap_data/ /usr/local/lib/python3.9/site-packages/mpl_toolkits/basemap_data/

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.