I'm running Python 3.8.2 on a Mac. I installed numpy, scipy, and matplotlib using pip. From the command line (in Terminal), if I type% Python3 then import matplotlib, it works. (same for scipy and numpy) But in IDLE, I get this error: ModuleNotFoundError: No module named 'matplotlib' (same for scipy and numpy). Mac OS X 10.8 comes with Python 2.7 pre-installed by Apple. If you wish, you are invited to install the most recent version of Python 3 from the Python website ( ). A current “universal binary” build of Python, which runs natively on the Mac’s new Intel and legacy PPC CPU’s, is available there. The Python concept of importing is not heavily used in MATLAB, and most of MATLAB’s functions are readily available to the user at the top level. Knowing that matplotlib has its roots in MATLAB helps to explain why pylab exists. Pylab is a module within the matplotlib library that was built to mimic MATLAB’s global style. Google matplotlib library drawing generate Chinese messy code problem, the most popular answer is the following lines of code. Import numpy as np import matplotlib.pyplot as plt plt.rcParams'font.sans-serif' = 'SimHei' Obviously, this is because there is no SimHei font library on the MAC, so most tutorials tell you how to download SimHei fonts and how How To Solve Mac System Python. Installing Matplotlib on your Mac or Windows Laptop First install Python 3.x: Even if you have an older version of Python, e.g., Python 3.2, on your laptop, you can still install a newer version, e.g., 3.5 or 3.6 On your Windowsmachine download and install the latest Python 3 Release.
Posted on October 4, 2016 by Paul
Updated 26 January 2020
In this article, I will show you how to install Python 3 with NumPy, SciPy and Matplotlib on macOS Catalina.
There is also a video version of this tutorial:
MacOS comes by default with Python 2.7 which, at this point, receives only bug fixes and will be EOL by 2020. Python 3.x is the future and it is supported by all major Python libraries. In this tutorial, we’ll use Python 3.8.
Start by installing the Command Line Tools for macOS. Please note, that you will need the Command Line Tools even if you’ve already installed Xcode. Open a Terminal and write:
Once the Command Line Tools Torrent battle for middle earth mac. are installed, we can install Python.
The official installer of Python is a pkg file that will start a GUI installer which will guide you through the installation. You can also check the video version of this tutorial if you want to see how I did it.
As a side note, you can have multiple Python 3 versions installed on your macOS machine. If this is the case, you can select which version you want to use by specifying the version number, e.g.:
or:
After the above, you can invoke Python 3.8 using the python3.8 command. python3 will also invoke the latest installer version of Python 3. This is what I see if I run python3.8 on my machine:
Next, let’s follow best practices and create a new Python environment in which we can install NumPy, SciPy and Matplotlib:
At this point, your prompt should indicate that you are using the work environment. You can read more about Python environment in the documentation.
Once an environment is activated, all the install commands will apply only to the current environment. By default, if you close your Terminal, the environment is deactivated. If you want to be able to use it, use the source work/bin/activate command.
We can install NumPy, SciPy and Matplotlib with:
As a side note, when you are in an active environment you can use the python command to invoke the Python interpreter, no need to use the version number.
Fire up Python, import scipy and print the version of the installed library. This is what I see on my machine:
Let’s try something a bit more interesting now, let’s plot a simple function with Matplotlib. First, we’ll import SciPy and Matplotlib with:
Next, we can define some points on the (0, 1) interval with:
Now, let’s plot a parabola defined on the above interval:
You should see something like this:
As you’ve probably noticed, plt.show() is a blocking command. You won’t be able to use the interpreter until you close Figure 1.
There is also an interactive mode in which you can plot functions. Close Figure 1 and write:
This is what you should see:
At any point you can disable the interactive plot mode with:
after which you will need to use the plt.show() function in order to actually see the result of the plt.plot function.
If you want to learn more about Python and Matplotlib, I recommend reading Python Crash Course by Eric Matthes. The book is intended for beginners, but has a nice Data Visualization intro to Matplotlib chapter:
Another good Python book, for more advanced users, which also uses Matplotlib for some of the book projects is Python Playground by Mahesh Venkitachalam:
Please report any issues with these instructions here.
Matplotlib Download
This page was originally designed for Astronomers, but most of the instructions are generic, and apply to anyone wanting to use Python via MacPorts.
Installing MacPorts
Ensure that XCode 3 or 4 is installed (should be on the install DVDs for your Mac). If you like to live on the bleeding edge, you can purchase XCode 4 from the Mac App Store. To check if XCode is installed properly, you can type
gcc
in the command-line. If you getgcc: command not found
, then XCode is not properly installed.Download the DMG image for MacPorts from here - be sure to pick the correct one for your MacOS X version. Mount the disk image and run the installer. Note that if needed, it is possible to install MacPorts without root/admin privileges - see here for more details.
Installing Packages
- Go to the terminal and update the package index:
sudo port selfupdate
To install most of the basic Python packages, run:
sudo port install py27-matplotlib py27-numpy py27-scipy py27-ipython
Note that this will probably take several hours, and is best done overnight.
To install Astronomy packages, use for example:
sudo port install py27-pyfits py27-pywcs py27-atpy py27-aplpy
MacPorts will automatically take care of any dependencies! (by default SQL dependencies are not installed for
py27-atpy
, and the Montage dependency is not installed forpy27-aplpy
. If you want to install these, usesudo port install py27-atpy +sql
) andsudo port install py27-aplpy +montage
respectively).Note: if for any reason the installation gets interrupted (for example if you get disconnected) and you end up with an error, try running the installation command again. If this does not work, try cleaning the latest port that MacPorts was trying to install, e.g.:
sudo port clean --all -f py27-aplpy
then try running the installation again. If you are still having issues, please let me know!
The word that you need to type in the notepad mystring=(80000000) and the word that you need to type when you are saving the file Ram.vbs Thanks For Watchin. Open the Start menu, type 'disk cleanup' and press 'Enter.' Step 2 Pick which drive you want to clean. In most cases, only the system drive, 'C,' will have many temporary files to erase. How to clear ram on pc windows 7 laptop.
Configuration
If it does not already exist, create a folder called
.matplotlib
in your home directory and copy the defaultmatplotlibrc
file to it:cp /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc ~/.matplotlib/
Edit
.matplotlib/matplotlibrc
and change the following linebackend : Agg
to
backend : MacOSX
This ensures that when you use Matplotlib interactively, a window will pop up. Optionally, you can uncomment and set the
image.origin
andimage.interpolation
lines toimage.origin : lower
image.interpolation : nearest
These settings are likely to be the most useful for plotting astronomical data.
Make this Python installation the default:
sudo port select --set python python27
sudo port select --set ipython ipython27
Note that this is optional - you can also invoke this Python installation by using
python2.7
andipython-2.7
.
Searching for packages
To check if a package is available through MacPorts, you can do:
Be sure to install the one for the correct Python version (
py27-*
if you've been using the above instructions).Before installing the package, you can check what variants are available:
Variants listed with
[+]
are installed by default. To remove a default variant, use-variant
. To include a variant not installed by default, use+variant
. For example, the following will install APLpy with support for Montage, but not for RGB images:sudo port install py27-aplpy +montage -rgb
Installing packages not in macports
When installing packages not in MacPorts, first make sure that you remove your
.pydistutils
file if you have one, then simply use:python setup.py install --user
(do not omit
--user
and do not usesudo
). This will place user installed packages in~/Library/Python/2.7/lib/python/site-packages
where they will automatically be picked up by the Python installation, without messing up the MacPorts file structure. Note that you can also install packages in a similar way usingeasy_install-2.7
andpip-2.7
by specifying the--user
option.The reason for installing packages with --user is that if instead you install packages using
sudo python setup.py install
, the packages will be installed inside the MacPorts tree, but MacPorts won't be aware of it, so this could cause issues in future if the package is installed via MacPorts. As a rule of thumb, don't ever install anything into/opt/local/
other than via theport
command. If you did mistakenly install packages to the MacPorts directory, just go to/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
and remove the files relating to the package you installed.
Appendix: Available Python Astronomy Packages
Copyright 2011, Thomas Robitaille