How to install NumPy for python 3.3.5 on Mac OSX 10.9

54,092

Solution 1

Welcome to both Python and Stack Overflow!

Your question is not at all uncommon. I've seen PhD graduates struggle with the exact same issues! While Python is a beautiful programming language with a very friendly community, getting started with the scientific Python stack can be quite a hassle.

There are two nice options for Python on Mac OS X, depending on how much time you want to invest into learning a particular set of tools. Both sets of tools are excellent and are well worth your time, but have a few tradeoffs. They are similar, though, in that they both will require you to spend some time in the terminal; I would recommend installing iTerm2 as your first step, if you haven't already.

Option 1: Homebrew

This option might be a bit more complicated, and may require more time invested up-front, but in the end can save you time and headaches because you have more control and freedom with how you want to set up Python and other command-line tools.

The first step is to install Homebrew. Currently, this is done with a single terminal command that will guide you through the installation process.

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

As part of it, you will have to install XCode (free from the App Store) and its associated command line tools. This is what makes this option time consuming.

Once you've installed Homebrew, you have access to a new command in the terminal, brew. You can use this command to install Python 3, NumPy, and Matplotlib.

# Install Python 3 that will be managed by Homebrew
brew install python3

# Get access to the scientific Python formulas
brew tap Homebrew/python

# Install Numpy and Matplotlib
brew install numpy --with-python3
brew install matplotlib --with-python3

Then you're good to go! This option gives you access to some powerful tools, like pip and brew. It means that in the future, when you want to install a new Python package, you should be able to pip install <that package>. Other command line tools, like for example git, can be installed with brew install git. It will make programming on Mac OS X a lot easier, in the end!

For some more information, see the Homebrew and Python wiki page.

Option 2: Anaconda

Anaconda is an all-in-one solution that will set up Python and all of the scientific Python tools all at once. All you have to do is download and install it!

Once installed, you should be able to run Python code that uses Numpy and Matplotlib. If you need a new Python package, you should be able to open up a terminal and do pip install <that package>. Some command-line tools and libraries are set up to install with conda install <tool>, but not nearly as many packages are available with conda as are available with brew. But, that might not be a big issue -- it depends what you end up using in the future!

The quick start guide is a good resource for the most common issues with Anaconda.

Solution 2

Installing numpy using pip didn't work for me on macOS 10.12.6. It was not detected. Instead I installed using brew, and it worked!

brew install numpy

To verify if it has been installed correctly,

python3
>>>import numpy as np

If no error is shown, means it has been installed correctly.

Solution 3

The easiest way would be to use pip (http://en.wikipedia.org/wiki/Pip_(package_manager)) which is a package manager for python packages like apt on Ubuntu or Homebrew on mac (which I would also recommend you get but is not exactly relevant in this situation). Pip will give you a list of python packages that you can search and install from and pip will handle the configuration and update of these packages. Pip by default comes with Python but is not installed but installing pip is very easy, see How do I install pip on macOS or OS X?, all you have to do is run sudo easy_install pip which will install pip (This assumes that you already have python installed on your system, if you don't install it before running this command). Then you can use pip to install numpy using sudo pip install numpy which will install the package numpy. You can also use pip to search packages using pip search <Package Name> which allows you to search through a list of python packages.

Note: I do not have enough reputation to comment on the answer above me but as I have used Anaconda I would like to point out that Anaconda is a full IDE and that installing Anaconda also installs another version of Python on your system which can cause issues when using the shell or running your python programs that require packages provided by Anaconda outside of the IDE.

Share:
54,092

Related videos on Youtube

DHorowitz
Author by

DHorowitz

Software Engineer working with backend web services but more familiar with AI work

Updated on July 05, 2022

Comments

  • DHorowitz
    DHorowitz almost 2 years

    So I'm currently trying to use python so that it will receive an email and open an attachment, and one of the imports I found required was matplotlib.pyplot as plt. This in turn required Numpy and matplotlib, of which matplotlib was easy to import but I can't for the life of me get NumPy to work. I tried going through the repository, unzipping the file, using Xcode, terminal, and homebrew and none of them work. I'm currently continuing to try with terminal but whenever I try to install NumPy it fails. A friend recommended typing in "sudo python setup.py build" followed by "sudo python setup.py install", however an error occurred saying that there was no such file or directory as setup.py. Any way anyone could explain a method of installing NumPy that will work for python 3.3 (Most I see are for 2.7 which I don't have) that won't drive me insane? (In case the question I'm asking seems ridiculously easy to some, I'm only a high school student who's never done anything like this before, so I'm desperately in need of help)

    • Bob
      Bob almost 10 years
      I'd recommend looking into setting up easy_install (or even better, pip) which will make this entire process and future processes much easier. You should be able to do this via the distribute pkg. See this post for more information on that: stackoverflow.com/questions/14335989/… From there you can just run the command easy_install numpy or pip install numpy. However it's up to you.
    • Emmanuel
      Emmanuel over 9 years
      The link for downloading Homebrew should be upgraded to ruby -e "$(curl -fsSL raw.githubusercontent.com/Homebrew/install/master/install)" Otherwise thanks a lot! This is very clear.
  • DHorowitz
    DHorowitz almost 10 years
    I tried using the Homebrew method as I already have that on my laptop, however when I got to brew install bumpy --with-python3 it resulted in an error that said "RuntimeError: Broken toolchain: cannot link a simple C program". I tried the diagnostic fixes for homebrew, but still not working.
  • tbekolay
    tbekolay almost 10 years
    Hmm, this seems to be a problem with NumPy right now. From this SO question, it looks like it might work if you do: export ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error‌​-in-future and then brew install numpy --with-python3
  • Christoph Burschka
    Christoph Burschka over 6 years
    Following these steps (option 1) now results in "Warning: numpy: this formula has no --with-python3 option so it will be ignored!" Also, the "Homebrew/python" tap is deprecated and empty.
  • Reine_Ran_
    Reine_Ran_ about 4 years
    brew tap Homebrew/python (Error: homebrew/python was deprecated. This tap is now empty as all its formulae were migrated.) and brew install numpy --with-python3 (Error: invalid option: --with-python3) doesn't work anymore. Just directly brew install numpy