PyPlot install on OSX

Dear,
I’m having trouble installing PyPlot on OSX Mojave. This is Julia 1.1.0. Whenever I install PyPlot on a fresh Julia, it fails to plot anything from the REPL, no backend is used, an error is throwers to the screen and Julia crashes and quits.
The only solution is to install IJulia, load PyPlot from there and plot something. Then it also works on the REPL… This also happened to me with Julia 1.0.3. A friend of mine also found this issue…
Hope it can be solved soon.
Best,
Ferran.

Do you have multiple Julia executables? What is the content of the file ~/.local/share/jupyter/kernels/julia-1.0/kernel.json and what is the output of Julia code Base.julia_cmd()?

It also is easier to find out the cause if you paste the whole error here.

Hi,
sorry for the delay in the reply… Yes I have several julia installs: 0.5, 0.6.4, 0.7 up to 1.1. The file you mention is missing, I can dive to

~/.local/share/

but the only thing there is a file

recently-used.xbel

and nothing else. The contents of Base.julia-cmd() is

`/Applications/Julia-1.1.app/Contents/Resources/julia/bin/julia -Cnative -J/Applications/Julia-1.1.app/Contents/Resources/julia/lib/julia/sys.dylib -g1`

I can not post the exact error thrown because after installing IJulia, the error solved itself. I can try to erase everything and start to install again to repeat the issue, though.
Best,
Ferran.

OK I tried in my second Mac (an iMac) with the same result. What I get when trying using PyPlot from the REPL after a fresh new install oj Julia-1.1 is:

julia> plot(rand(1000),rand(1000))
2019-01-26 10:57:02.491 julia[33945:79942] -[NSApplication _setup:]: unrecognized selector sent to instance 0x7fb4c11233e0
2019-01-26 10:57:02.491 julia[33945:79942] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication _setup:]: unrecognized selector sent to instance 0x7fb4c11233e0'
*** 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: 15552862 (Pool: 15550194; Big: 2668); GC: 33
Abort trap: 6

…and that’s the end of the story :frowning:
Thanks a lot,
Ferran.

…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: TkAgg backend on macOS aborts · Issue #410 · JuliaPy/PyPlot.jl · GitHub, 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! Pkg · The Julia Language

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: GitHub - mitmath/julia-mit: Tutorials and information on the Julia language for MIT numerical-computation courses.

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