PyPlot install on OSX

…and once again, installing IJulia solves the problem on the REPL.

It’s sometimes useful to browse through the issues on github, since others may have had the same problem. And sometimes there’s a solution, too.

Sorry, it was for Linux. In macOS, it looks like it’s ~/Library/Jupyter/kernels/julia-1.0/kernel.json.

See: https://jupyter.readthedocs.io/en/latest/projects/jupyter-directories.html#data-files

This is the very puzzling part. My guess is that Python executable you use is from anaconda (i.e., using PyCall; PyCall.pyprogramname prints a path inside a conda environment) and then installing IJulia triggers installation of some conda packages including some matplotlib backend that is happened to work on macOS.

If that’s the case and if you are curious, I think running Conda.runconda(`list`) while you are having the error and also after installing IJulia fixes the issue may give you some hints.

I’m having this problem as well and it just started recently. I can plot with no problem from Anaconda and using PyPlot on the REPL fails, IJulia does not seem to help. The Plot package does not do what i want nearly as well as PyPlot.

I am new to Julia and some of the features of the language could help me get my job done.
This is not one of them. If this is a bug that will be fixed, that’s ok. If I’m supposed to
fix it, that is not ok. I do not have the time or the skill set for this. I am a user, not a developer.

How do you load PyPlot from IJulia in the REPL? What commands can I invoke to do this?

Thanks.

I’m not sure this is what people need, but this is the message I get from the REPL

2019-05-08 20:37:57.760 julia[48530:3754080] -[NSApplication _setup:]: unrecognized selector sent to instance 0x7fa3d8dc4570

2019-05-08 20:37:57.760 julia[48530:3754080] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[NSApplication _setup:]: unrecognized selector sent to instance 0x7fa3d8dc4570’

*** First throw call stack:

(

)

libc++abi.dylib: terminating with uncaught exception of type NSException

signal (6): Abort trap: 6

in expression starting at no file:0

__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)

Allocations: 17626913 (Pool: 17623549; Big: 3364); GC: 38

Abort

Did you search the PyPlot issues for this error message? You would have been quickly led to: https://github.com/JuliaPy/PyPlot.jl/issues/410, which is an upstream problem with the tkagg backend on MacOS. (You can check what Matplotlib backend you are using with PyPlot.backend.)

About a month ago I changed PyPlot to default to qt5 on MacOS, so if you update your packages hopefully the problem will go away. You can also manually change your default backend with the MPLBACKEND environment variable or by editing your .matplotlibrc file.

Thanks for the response. I think I’m installing qt5 right now. Just finished and the new backend seems to work in the REPL Thanks a lot!!!

I installed PyPlot from scratch at least three time today with the same problem. qt5 was not around until I installed it just now. The package should have been fresh as of today. What should I have done differently?

One of my jobs over the summer is to prepare a presentation to some of our faculty and students on Julia. The question is if it is a reasonable alternative to matlab in our entry-level courses.

Problems like this tell me the answer is no. There are things I’m willing to deal with for my own work that I’m not willing to help 30+ students figure out. This issue is one of them. If I can’t tell them to install PyPlot and be done with it, then plotting in Julia is not working well enough. Until I worked through enough threads to figure out that

using Conda; Conda.add(“pyqt”)

might solve my problem, I was ready to give up. Students can’t do that, they’ll either give up or bother me.

Anyhow, thanks a lot. I’m in Hong Kong now and about to crash. If PyPlot still works in my jupyer notebook tomorrow, then I’m ok for now.

PyPlot can only install pyqt automatically if you are using the Conda.jl Python. If you have configured PyCall to use your own Python installation, then you are responsible for installing things yourself.

If students have to install software themselves, then with any large free-software system involving disparate packages (Python too) you are going to run into a long tail of installation problems, especially on older laptops. In a software-development/computer-science course, we typically have an army of TAs that can help students out, but in a math or science course that only incidentally involves programming this is typically not an option.

The solution that we’ve used (for intro classes with 200 students) is to allow students to run their software in the cloud — they just visit a certain URL in their browser and get a nice Jupyter notebook (or JupyterLab) interface to Julia, with all the necessary packages pre-installed. One option for this is http://juliabox.com, but this is transitioning to a paid service. Another option that we are exploring is setting up a JupyterHub server — this has already been done at multiple universities for multiple languages. The costs seem to be quite modest even for a university-wide service. And there are other hosting services too.

The notebook interface is great for teaching — not only can we post lecture notebooks that mix runnable code, text, equations, and graphics, but also we can give them problem sets in the same format, with sample code that they need to flesh out and run, and they can turn in their computational homework simply by submitting their notebook (printing to PDF) since it has both their code and their results.

Hi Steven, you’ve been immensely helpful. I’m getting plots in anaconda and the REPL.

I am not a python user at all and don’t think I configured python. However, there is a 2.7 installation in /System/Library/Frameworks that may be part of Mojave. Is that the problem? Could installing Anadonda first have caused the problem? I’d like to be able to tell people how to get things working with a list like this

Install Anaconda
Install Juila
while Pkgx = IJulia, PyPlot, Conda (more?)
Do add Pkgx
Do using Pkgx
end

will that the the correct matplotlib backend into PyPlot even with the 2.7 version in a System file? Should I still have to explicitly add pyqt?

What do I tell Python users. Is what I finally came up with (using Conda + Conda.add(“pyqt”)) going to do the job for them?

The people who will attend my presentation will want to play with Julia themselves and expect me to tell them how to get started. The math part is going well, but

Putting the install in the cloud would work ok for notebooks, but we’d need the students to use the REPL and they’ll want to use their own computers. This is also a problem with Python, which is why we are a Matlab shop.

I’m also worried about reproducability in publications. I’m using Julia in a paper for the first time and do not want the code I put in supplementary materials to fail to run. I’m not the only Julia/Pyton user who worries about this.

Thanks again,

– Tim

You will likely be confronted with such environment issues with both Julia and Python (and other languages or setups like Jupyter environments etc). Most operating systems come with Python 2.7, but people are installing anaconda/miniconda/pyenv/younameit and then Python 3 from apt/yum/pacman Linux repositories or homebrew on macOS and whatever voodoo on Windows. Libraries, packages and their versions will mix up and things are working and breaking randomly.
I gave a few programming courses over the last year and I’d say every single problematic laptop setup was uniquely ruined by creative modifications of PATH, PYTHONPATH, LD_LIBRARY_PATH, messed up .login/.profile/.bashrc/.zshrc etc.

Sorry for this not-so-constructive reply but you have to deal with this mess :wink: There is no receipt which will work for sure (at least me and my team have not found anything close yet). If you plan to give courses on a regular basis, I’d recommend using a central service like juliabox.org or a similar local setup (just talk to your IT administrator) and give the students some good resources where they can figure out how to setup their working environments weeks in advance, including a test-script which they can run to verify that everything works before they join your lecture. We managed to get the fraction of “nothing-works-on-my-laptop-users” down to around 10% with this strategy.

I’m also worried about reproducability in publications. I’m using Julia in a paper for the first time and do not want the code I put in supplementary materials to fail to run. I’m not the only Julia/Pyton user who worries about this.

Have a look at the new package system and how to define environments; they are fully reproducible! https://docs.julialang.org/en/v1/stdlib/Pkg/index.html

1 Like

You don’t need Anaconda. Julia (PyCall, rather, via the Conda.jl package) will install it for you unless you have set the PYTHON environment variable.

For reference, these are the instructions I give students at MIT: https://github.com/mitmath/julia-mit

1 Like

Why? We use notebooks for all our interactive coursework.

Thanks, may I share this with the people here at NCSU?

The language in this course usually becomes one of the languages a student will use for a PhD project. You can’t publish a notebook in our thesis format, at least not yet. I also can’t see working on a research project via notebooks, but that may be because I’m old. I’m using the REPL for most programming work and the notebooks for presentations and group meetings.

I usually do my analyses in notebooks, where code which is too specific to be put it in a reusable library lives together with plots, comments and equations, using a reproducible environment. The REPL to me (no matter which language) is just a throw-away/try-out thing with a short lifespan :wink: I don’t understand how the main programming work could be done inside the REPL, but maybe I am too young :smiley: I try things out, put them in packages/libraries and do the analysis in self-contained notebooks. That’s how it remains reproducible and shareable.

Edit: after all, a Jupyter notebook is just a REPL with automatic session recording and tons of optional features.

1 Like

Actually notebooks can be converted to LaTeX.

Notebooks (or the REPL) are for interactive work. For large (PhD-level) programming projects I think you typically want to put together proper Julia modules and use general-purpose editors (though JupyterLab is an option) on your own computer. But that’s very different from classroom usage … if someone is setting out to do PhD-level numerical work, learning how to install software should not be the biggest hurdle.

Of course!

Yessir, I am not a young man.

My workflow is having Julia/Matlab open in a terminal window + several other windows running vi. I don’t even use the matlab desktop for anything but profiling. My students do most of their work in notebooks and see me as a relic.

The issue with publishing notebooks, which is one reason I got interested in Julia, is not that you can’t get LaTeX. It’s the postprocessing you have to do to meeting the rules for journals, book publishers, and universities. I know people who are close to figuring this out for SIAM books and python and I’m hoping to do something like that with Julia in a few years. I’ve been told by someone who’s put major effort into this that it can be a lot of work, but the tools are coming online pretty rapidly.

I’ve been more or less sold on notebooks for reproducability. I got spooked when PyPlot stopped working, but I’m planning on a notebook for my next paper.

You can always export the plain vanilla source code from the notebook (as a .jl file). Everything you can do at the REPL, you can do in a notebook (except stuff that relies on terminal interaction).

Using a notebook, or an editor + REPL is a matter of preference, they are mostly functionally equivalent. I am not trying to talk you into using a notebook — I use Emacs myself, simply because I find that the editing capabilities of notebook interfaces just don’t compare (as a vi user, I think you may feel the same). But it is a perfectly fine choice for some people.

1 Like

FYI, both Jupyter Notebook and Jupyter Lab come with an in-browser terminal app which can be used for simple things. You can use Vim in it (well, kind of…) although it’s not super smooth. Jupyter Lab also has REPL which can be used without notebook file attached to it (if you know qtconsole it’s very similar).

1 Like