
Installing the SciPy stack
To install the SciPy stack, execute each of the following commands on a Terminal window:
pip3 install --user numpy scipy matplotlib
pip3 install --user ipython jupyter
pip3 install --user pandas sympy nose
We now need to adjust the PATH variable in the .bash_profile file. Notice that you might not have a .bash_profile yet. If you do, it is important to make a backup copy of it by running the following commands at the command line:
cd
cp .bash_profile .bash_profile.bak
If you get a message stating that .bash_profile does not exits, do not worry. We will create one now.
Start your text editor and open the .bash_profile file. For example, to use nano, a simple text editor included with macOS, run the following in a Terminal window:
cd
nano .bash_profile
This will create .bash_profile if it still does not exist. Add the following line at the end of file, where you need to replace 3.x by the version of Python you have installed:
export PATH="$HOME/Library/Python/3.x/bin:$PATH"
Save the file, close the editor, and run the following command from the Terminal window:
source .bash_profile
This completes the installation of a basic SciPy stack. To test the setup, start Python 3 in the Terminal window by running the following command:
python3
To check that all packages we need were installed, execute the following lines at the >>> Python prompt. Notice that there will be no output, and, as long as there are no errors, the installation is correct:
import numpy
import scipy
import matplotlib
import IPython
import pandas
import sympy
import nose
You can now exit the Python shell by running the following statement at the prompt:
quit()
Let's now check that IPython is accessible from the command line. Run the following line from the Terminal window:
ipython
This will start IPython, an alternative Python shell with many added features that is required to run Jupyter. A message similar to the following will be printed:
Python 3.x.x (default, Apr 4 2017, 09:40:21)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.0.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]:
If you get an error when trying to start IPython, the PATH variable was probably not set correctly in the .bash_profile file. You can check the current value of the PATH variable by entering the echo $PATH command. If the path is not correct, edit .bash_profile as indicated previously to correct the error.
Exit Python by entering, the following command in the IPython prompt:
quit()
Let's now test if we can run the Jupyter Notebook. Run the following command from the Terminal window:
jupyter notebook
If all is correct, you will see a series of startup messages in the Terminal, and the Jupyter Notebook will eventually start on your browser. If you get an error message, you probably have an incorrectly configured PATH variable. Check the preceding tip box for instructions on how to fix it.
This finishes the installation of Python and the SciPy stack in macOS. Please proceed to the Setting up a virtual environment section.