-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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 fails inside virtualenv #609
Comments
Most likely you have a bad-behaving (it won't pop up, it won't take focus) window behind your current terminal. Try hiding all apps, then run your test and then move or resize the terminal window (mission control and other exposé-like stuff won't help). See matplotlib/matplotlib#2881 and related. This is most likely due to virtualenv not reproducing the Framework-install, I'm trying to fix that myself. |
Any updates on this? Has anybody located the issue (yup, no Framework installs, but where exactly does it fail?) already? |
Just for sake of documentation, http://wiki.wxpython.org/wxPythonVirtualenvOnMac solves this issue by calling systemwide python with a PYTHONHOME environment variable. |
Note that copying your global python executable into the virtualenv |
No update on my side, actually back then I needed matplotlib for a brief while and in order to produce some plot so I didn't spent time on that. You may want to provide a reproducible example to help developers tracking the bug, see http://sscce.org |
Reproducible example: The following commandline script exhibits the bug:
The following commandline script does not exhibit the bug:
|
I can confirm that the code from gldnspud/virtualenv-pythonw-osx does fix the issue I am having. Is there a way we can integrate it into mainline virtualenv? |
We've had the same problem with Pygame Zero, running in a virtualenv on a Mac. We have a workaround, described in this thread. It means substituting the system Framework Python for the virtualenv one that can't handle windowing properly on a Mac. |
@agiledata how's that going to work? On my Yosemite system I don't have '/Library/Frameworks/Python.framework/Versions/' at all, and anyway the system-shipped Python framework doesn't have 3.x |
@anddam We made the fix for Pygame Zero, where having Python 3 installed is a requirement. But the principle is the same, whichever Python version you want to substitute, just run a full framework Python with the environment from virtualenv. |
As of matplotlib 1.5.0 you are required to use ugly hacks to make it work in virtualenvs. Can we please fix this issue already? |
@nils-werner You have always needed ugly workarounds to make it work. It's just now that we added a check and fail hard rather than trying to open a broken window that is borderline useless and can't be put in the foreground. |
@jenshnielsen I am not blaming matplotlib but virtualenv. |
I'm more inclined at this point to blame matplotlib to be honest. I'm not even using virtualenv right now and I'm seeing all the same issues after trying all their hacks to make it work with virtualenv. |
@optimuspaul I am sorry but you are simply wrong. As it is there is no way you can run a Framework build inside a virtualenv. It simply doesn't work. That means that you CANNOT interact reliably with the GUI frameworks inside a virtual env without work arounds. The work around we have given are only meant to be used inside a virtual env. How you managed to apply them outside is beyond me but it must be a user error at your side. The work arounds do work inside virtual envs and that has been confirmed by several users. If you want anyone to to help you with your issue you better provide more than a rant without details claiming that we broke stuff. We actually did spent time investigating this and trying to fix the issue for users. |
And if you are seeing the issue outside a virtual env without workarounds then it probably means that your python build is just not a framework build in which case you will need to reinstall python as a framework build if you want to interact with OSX gui frameworks. |
Finally I solved this problem by this article, http://www.wirywolf.com/2016/01/pyplot-in-jupyter-inside-pyenv-on-el-capitan.html It works!! |
@wisherica It is still a work around and does not work out the box. |
I'm having issues with this on Python 3.5. Installed the frameworkpython script with pyver=3.5 in bin but I still get the backend error issue. Any clues? It works fine when I do this with Python 2.7 but not on Python 3.5 |
Im using the following slightly tweeked from the original which works with both python 2.7 and 3.5. Both of the default non virtual env are in /usr/local/bin
|
I removed the frameworkpython script from my virtualenv |
Can you run matplotlib outside the virtualenv. It is possible that |
I ran the python3.5 interpreter, imported |
I just installed python3.5.1 from python.org and it works for me. Both versions of the script basically amount to:
were test.py is simply
Sorry to not be more helpful |
Thanks for your help so far! I can pinpoint exactly where its not working. Frameworkpython works with ipython in the terminal and with the method you mentioned. However, when I run |
Finally got it to work using @wlsherica method. I don't know enough about Python to say but it could be specific to running matplotlib.pyplot in jupyter-notebook on OSX El Capitan. Thanks for your help @wisherica and @jenshnielsen! |
I'm hitting the same issue, just in a way more annoying way. I'm trying to run the unit tests testing part of a Python module with
|
Because matplotlib sets the backend at import time of pyplot. If you want a different backend I suggest selecting it before importing it or configuring another default backend.
|
You can also set the default backend in the matplotlibrc file if you can't edit your unit test files. |
Yep, I've just found this solution actually just now @jenshnielsen @RexFuzzle, thanks for the help! Regardless, while I understand that I basically know nothing about the inner workings of |
Is this solved? If so, can someone close it? |
It is absolutely Not Solved. Matplotlib has documented various workarounds. The best one is to not use virtualenv but pyvenv which works correctly |
There is someone that use also virtualenvwrapper? In that case I used a suggested workaround that matplotlib has in its FAQ that is create the environment with pyvenv (of course if you need Python 3). The interesting thing is that if you create the environment with pyvenv inside the WORKON_HOME folder virtualenvwrapper still works fine and I can use matplotlib without problem inside that environment. Hope this thing can help and that I'm not off topic. |
Pyenv (not pyvenv) and virtualenv are two different levels of sandboxing. I'm running both, pyenv to define the python version per project and pipenv (which uses virtualenv) to define modules per project. Pyenv doesn't provide a way to have multiple instances of the same version of python. It would be really good to get virtualenv working with properly. Any updates on this? |
It works fine with pyenv virtualenv combined with pyenv provided that you remember to build the pyenv python version as a framework build as documented here It also works with venv instead of virtualenv for python3 which I think is what was meant by "pyvenv" above. |
@jenshnielsen Even if I’ve built pyenv python as a framework matplotlib fails in an virtualenv built with pipenv. I’ve also understood that matplotlib works with python3 venv, but there is an issue open to get pipenv to work with python3 venv which is problematic for all kinds of weird reasons. If this is fixable in virtualenv that would be really good. |
I know, I just tried to help you by telling you that it works with pyenv virtualenv which you can use to install create multiple pyenv envs with the same python version, since you claimed that pyenv does not handle that |
@jenshnielsen Thanks for the tip, you are right that pyenv virtualenv provides a way to have multiple instances of the same version of python with pyenv and automatically switching between them per project. It also might be possible to install dependency modules from Pipfile into the pyenv virtualenv with pipenv using the flag to install to global python (pyenv virtualenv in this case). Since you said previously that this combo works fine, it can be a viable option in the scenario I was thinking about (using ”only” pyenv). |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Just add a comment if you want to keep it open. Thank you for your contributions. |
Matplotlib doesn't show the figure window from within a virtualenv. I've tried many combinations (e.g. intalling using pip, using easy_install, compiling from source, using --system-site-packages, different versions, etc.) with no luck. The test that makes me think is a virtualenv issue is that if I try to use my working system-wide matplotlib from virtualenv, I don't see a figure. In other words, if I run this:
it works ok (shows the figure). Then, if I create a virtualenv with
--system-site-packages
and run the same script, it doesn't work. That is:fails (it hangs and doesn't even return). I need to kill the process.
Btw, the
plotTest.py
if the following:FWIW, in both cases I do see the line printing
MacOSX
as the backend.The text was updated successfully, but these errors were encountered: