0
votes

I am on Ubuntu 16.04.4 LTS. Currently learning Julia. Julia uses PyPlot as it backend for plotting. PyPlot requires Python and matplotlib installed on system.

My Ubuntu came with both Python(2 & 3) installed. I installed matplotlib using this command sudo apt-get install python3-matplotlib . I checked matplotlib version and it is Matplotlib 1.5.1. But whenerver I try to plot using PyPlot as backend julia> pyplot(),

Julia's output is : WARNING: You are using Matplotlib 1.5.1, which is no longer officialy supported by the Plots community. To ensure smooth Plots.jl integration update your Matplotlib library to a version >= 2.0.0

Thus I tried to upgrade matplotlib using the pip, and it says my matplotlib version is up-to-date. From the output of pip command sudo pip install --upgrade matplotlib is:

The directory '/home/yousuf/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. The directory '/home/yousuf/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Requirement already up-to-date: matplotlib in /usr/local/lib/python2.7/dist-packages Requirement already up-to-date: numpy>=1.7.1 in /usr/local/lib/python2.7/dist-packages (from matplotlib) Requirement already up-to-date: six>=1.10 in /usr/local/lib/python2.7/dist-packages (from matplotlib) Requirement already up-to-date: python-dateutil>=2.1 in /usr/local/lib/python2.7/dist-packages (from matplotlib) Requirement already up-to-date: backports.functools_lru_cache in /usr/local/lib/python2.7/dist-packages (from matplotlib) Requirement already up-to-date: subprocess32 in /usr/local/lib/python2.7/dist-packages (from matplotlib) Requirement already up-to-date: pytz in /usr/local/lib/python2.7/dist-packages (from matplotlib) Requirement already up-to-date: cycler>=0.10 in /usr/local/lib/python2.7/dist-packages (from matplotlib) Requirement already up-to-date: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python2.7/dist-packages (from matplotlib)

It seems, from this output, pip tries to upgrade matplotlib for Python2 and 1.5.1 is the latest version for it. But Julia and PyPlot uses Python3 as I set up to use it.

3
The recommended backend for Plots.jl is GR. I would give that a try first.Chris Rackauckas
With pip you should not use sudo and the option --user at the same time. Otherwise the file in your home directory will belong to the root user.Alex338207
@Alex338207, Opps. My mistake. That was not the command I ran, actual command would be "sudo pip install --upgrade matplotlib". I've updated the question's details.Yousuf
@Chris Rackauckas, GR means Gadfly? My instruction requires me to use PyPlot as backend.Yousuf
No, GR means using the GR.jl backend for Plots.jl. It is the recommended backend for Plots.jl and will be made the default in a few days (it has a shiny new terminal). I am surprised that PyPlot would be preferred by your instructor.Chris Rackauckas

3 Answers

4
votes

I found the solution by using pip3. To install pip3 on Ubuntu:

sudo apt install python3-pip

Now upgrade matplotlib for Python 3.x.x using pip3:

sudo pip3 install --upgrade matplotlib

sudo apt-get update

You are good to go.

2
votes

If you install matplotlib using apt-get, you should not interfere with the installed version. What I mean is that you should not sudo pip3 install --upgrade matplotlib as this might have other side-effects when you sudo apt-get dist-upgrade later on.

You'd better use pip3 install --user --upgrade matplotlib to keep the packages in your local /home/<user>/.local/{bin,lib,etc,share} folders properly. This way, your python distributions will be using the latest packages installed, and your package manager will not have any trouble later on.

EDIT. sudo apt-get update does not update any packages. It simply updates the cache of your package manager, i.e., fetches the latest version information for the provided packages by Ubuntu. sudo apt-get dist-upgrade will install all the updates. And this command might have side-effects such as failures and/or replacing your sudo pip3 install --upgrade matplotlib installed version of matplotlib. Generally, it is good practice to let the package manager do its job when installing packages on a system level.

2
votes

First, uninstall the older version using:

pip uninstall matplotlib

Then, install the latest version using:

pip install matplotlib

Matplotlib will be updated to the latest version. You can check using:

pip list