Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matplotlib with enableQt = false will attempt to use Qt and if Qt is imported by another package #85046

Closed
shuhaowu opened this issue Apr 12, 2020 · 11 comments
Labels

Comments

@shuhaowu
Copy link
Contributor

Describe the bug
If you construct a nix-shell with matplotlib in its default setting (enableTk = true; enableQt = false;) with another app that depends on Qt, matplotlib will try to use the Qt backend unless matplotlib.use("TkAgg") is called at the beginning of the Python code that you write.

To Reproduce
Steps to reproduce the behavior:

  1. Create a nix shell with a PySide2 app with matplotlib
  2. import matplotlib.pyplot as plt; plt.figure()
  3. Observe crash:
qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem

Expected behavior
Matplotlib should use the TK backend.

Workaround
Add

import matplotlib
matplotlib.use("TkAgg")

to the top of the python script using matplotlib.

Metadata

these paths will be fetched (0.00 MiB download, 0.00 MiB unpacked):
  /nix/store/8pkkw458w4q00gp9yrcg95mxc72nzd85-nix-info
copying path '/nix/store/8pkkw458w4q00gp9yrcg95mxc72nzd85-nix-info' from 'https://cache.nixos.org'...
 - system: `"x86_64-linux"`
 - host os: `Linux 4.15.0-91-generic, Ubuntu, 16.04.6 LTS (Xenial Xerus)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.3`
 - channels(root): `"nixpkgs-20.09pre217526.9b3515eb95d"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`


Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module:
@shuhaowu shuhaowu added the 0.kind: bug Something is broken label Apr 12, 2020
@teto
Copy link
Member

teto commented Apr 12, 2020

isn't that a matplotlib issue ? they shouldn't rely on an absent backend

@shuhaowu
Copy link
Contributor Author

I suspect matplotlib is detecting if it can import pyside, which is possible as pyside exist in this nix shell environment. However, if enableqt is explicitly false, the nix build of matplotlob shouldn't try to use it IMO.

@doronbehar
Copy link
Contributor

Sounds like a matplot issue to me as well. You see, according to matplotlib's default.nix, pretty much the only difference between building it with qt or without it, is the existence of pyqt5 in it's propagatedBuildInputs:

propagatedBuildInputs =
[ cycler dateutil numpy pyparsing tornado freetype kiwisolver
libpng mock pytz ]
++ stdenv.lib.optional (pythonOlder "3.3") backports_functools_lru_cache
++ stdenv.lib.optionals enableGtk3 [ cairo pycairo gtk3 gobject-introspection pygobject3 ]
++ stdenv.lib.optionals enableTk [ tcl tk tkinter libX11 ]
++ stdenv.lib.optionals enableQt [ pyqt5 ];

I also tested the resulting outputs of matplotlib with and without qt using dirdiff and the only main difference is $out/nix-support/propagated-build-inputs.

When nix-shell creates the environment, it puts in PYTHONPATH all propagatedBuildInputs of all packages you add to the environment that python eventually sees. At this point, I wonder how it detects qt5 in it's environment as pyside2 doesn't require pyqt5 but only qt5.

This also conflicts with their docs: https://matplotlib.org/3.2.1/users/installing.html#install-requirements . Please report this upstream @shuhaowu .

As for this error:

qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem

This is a known issue with pretty much every python library that requires certain environment to perform GUI stuff. See #25351 . See a possible fix in #83321 and discussions / broader ideas:

@stale
Copy link

stale bot commented Oct 10, 2020

Hello, I'm a bot and I thank you in the name of the community for opening this issue.

To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it.

If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them.

Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 10, 2020
@dschrempf
Copy link
Contributor

dschrempf commented May 12, 2021

This is still an issue, I just bumped into it.

EDIT: I realized this only happens in ipython, it does not happen in jupyter-console (I guess because no graphical interface is assumed in the latter case).

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label May 12, 2021
@stale
Copy link

stale bot commented Nov 9, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 9, 2021
@dschrempf
Copy link
Contributor

I just tried plotting a figure with matplotlib default setting (no config files, no additional settings in Nix config), and it worked. I think it uses the tk backend.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 13, 2021
@doronbehar
Copy link
Contributor

I too can confirm the issue is fixed. As mentioned earlier, this was an upstream issue IMO and it is fixed now so it seems.

@ShamrockLee
Copy link
Contributor

Has anyone reported it upstream?

@dschrempf
Copy link
Contributor

Is this an upstream issue? Is so, I do not think so.

@doronbehar
Copy link
Contributor

You can open a new issue if you still experience this issue, when we closed this, we weren't sure what exactly upstream did that fixed this, we just observed this is no longer an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants