onsdag den 30. marts 2016

Installing python with matplotlib and basemap on mac

In the last couple of months I have installed python on two different macs. It took forever to get matplotlib and basemap to work the first time, before I understood that I could not use the build-in python from apple. I ended up installing python enthought using homebrew, and I promised myself that I would write down how to do it after the second installation. But I forgot. And now it's been a while, I got a new laptop and I have to install python once again.
So here it goes, for my future self and anybody else who can use it.


  • Install Xcode from the app store. It's free and can be found here. Make sure to open Xcode and agree to it's terms and conditions.

  • Download and install the enthought canopy python distribution. This is their free python version, which entails numpy, scipy and matplotlib.
    To finish the canopy installation it is necessary to open the application Canopy. If this is done by double-clicking the icon, it will give the error message "Enthought Canopy can't be opened because it is from an unidentified developer". To get around this, it is necessary to right-click (CTRL-click) on the icon of Canopy and choose "open". In the pop-up window choose "Open" - and the program installs.
    After this a new pop-up window appears asking "Do you want to make Canopy your default Python environment?", to which you answer "yes". 

  • Now we want install homebrew. Homebrew is a package manager similar to macports and fink. It is installed by opening the terminal and typing:

    $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 

    You will be asked for your password and need to wait a few moments for the installation.
  • To install the Geos package type:

    $ brew install gdal 


    Note the location of the Geos library. For me:  /usr/local/Cellar/geos/3.5.0 
    The path written in the last line after installation indicates the location of the geos library, for me this was: /usr/local/Cellar/gdal/1.11.3_1  
  • To install Basemap it must first be downloaded. On this page, choose the newest version and download the tar-file for mac. Then go to the Downloads folder in the terminal and unpack the files:

    $ cd ~/Downloads/
    $ tar xf basemap-1.0.7.tar.gz 

    This creates a new folder with the name of the tar file, in my case ~/Downloads/basemap-1.0.7. You need to enter that folder:

    $ cd basemap-1.0.7
  • Then export the directory of geos library noted above and install baseman:

    $ export GEOS_DIR=/usr/local/Cellar/geos/3.5.0/
    To build and install write:

    $ sudo python setup.py build
    $ sudo python setup.py install

    You will be asked for your password, and the installation will take a little while to run.
  • And now python should work with basemap. You can test in the terminal by writing opening python and loading basemap:

    $ python
    >>> from mpl_toolkits import Basemap

    If this works without error messages everything is fine. For me it worked for the last two computers - this time it worked after a restart. Awesome.

11 kommentarer:

  1. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    Devops Training in Chennai

    Devops Training in Bangalore

    Devops Training in pune

    SvarSlet
  2. I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post I would like to read this
    python training in OMR
    python training in chennai

    SvarSlet
  3. That was a great message in my carrier, and It's wonderful commands like mind relaxes with understand words of knowledge by information's.
    java training in annanagar | java training in chennai


    java training in marathahalli | java training in btm layout

    SvarSlet
  4. I always enjoy reading quality articles by an individual who is obviously knowledgeable on their chosen subject. Ill be watching this post with much interest. Keep up the great work, I will be back

    Data Science course in kalyan nagar | Data Science course in OMR
    Data Science course in chennai | Data science course in velachery
    Data science course in jaya nagar

    SvarSlet
  5. Have you been thinking about the power sources and the tiles whom use blocks I wanted to thank you for this great read!! I definitely enjoyed every little bit of it and I have you bookmarked to check out the new stuff you post

    angularjs online Training

    angularjs Training in marathahalli

    angularjs interview questions and answers

    angularjs Training in bangalore

    angularjs Training in bangalore

    SvarSlet
  6. Your blog is informative and helpful. Continue sharing more like this.
    Devops Training in Chennai | Devops Training Institute in Chennai

    SvarSlet
  7. Title:
    Top Big Data Training Institute in Chennai | Infycle Technologies

    Description:
    Learn Big Data for excellent job opportunities from Infycle Technologies, the best Big Data training institute in Chennai. Infycle Technologies gives the most trustworthy Big Data Training in Chennai, with full hands-on practical training from expert trainers in the field. Along with that, the placement interviews will be arranged for the candidates, so that, they can meet the job interviews without missing them. Transform your career to the next level by dialing 7502633633 to Infycle Technologies and grab a free demo to know more
    best training institute in chennai

    SvarSlet
  8. Infycle Technologies, the best software training institute cum placement center in Chennai offers the No.1 Digital Marketing course in Chennai for freshers, students, and tech professionals at the best offers. In addition to the Digital Marketing Training, other in-demand courses such as AWS, DevOps, Data Science, Python, Selenium, Big Data, Java, Power BI, Oracle will also be trained with 100% practical classes. After the completion of training, the trainees will be sent for placement interviews in the top MNC's. Call 7504633633 to get more info and a free demo. No.1 Digital Marketing Course in Chennai | Infycle Technologies

    SvarSlet