Matplotlib wxWidget plot missing button images on Cygwin - matplotlib

Screenshot:
What can be cause for this issue: is it Cygwin issue, or wx/wxPython issue, or Matplotlib issue?
Other than this error popping about missing button images on every plot, everything works fine
Day after: As I compiled wx to use native Windows graphic interface (no need to install X server and gtk) it's basically Windows compile (not Cygwin compile) so it does not understand Cygwin POSIX paths while Cygwin packages can use it.
It's not just MPL that has problems this way but any wx package that passes Cygwin resource as filename to wx. One workaround is to pass python object instead path, so for above example this can be workaround like this:
Matplotlib uses _load_bitmap(filename as str) function to pass those buttons graphics to wx through wx.Bitmap(filename). Patching backend_wx.py like this:
# bmp = wx.Bitmap(bmpFilename)
wxf = open(bmpFilename, 'rb')
bmp = wx.BitmapFromImage(wx.ImageFromStream(wxf, wx.BITMAP_TYPE_ANY))
wxf.close()
resolves this for Matplotlib and runs without issues
I'm interested in more robust solution that would work for all wx applications

Related

Send help in the form of someone who knows python well

I am currently well versed in java, but I am trying to get into python. I know the basics, but am struggling with package use and implementation into source code.
I have successfully installed both numpy and Pillow (or PIL):
Click here for cmd telling me both packages have been installed
When I typed import numpy into cmd running python, it worked no problem, but now I've tried to open IDLE and import it there, and written source code trying to import it and utalise parts of the numpy lib but it always gives me a ModuleNotFoundError
python idle shell import vs. cmd import
My folder layout is a little wacky:
C:
..Users
....B
......ForImagingProject
........PYTHON
..........(python standard subfolders)
..........Lib
............site-packages
..............numpy and PIL and pip here
Any and all help would be appreciated
Thanks ~ B
EDIT: I messed up and my IDLE shortcut was running idle.pyw instead of idle.bat. Everything working smoothly now.
Check your IDLE's python executable. Is it the same one as in your cmd prompt?
The easiest way to check is to run this:
import sys
print(sys.path)
Look for something like
'PATH_TO_PYTHON/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7'or
'PATH_TO_PYTHON/Frameworks/Python.framework/Versions/2.7/lib/python2.7'
Make sure this is the same in both the IDLE and in cmd.
The reason the shell I was working in was unable to recognize the module was because my IDLE shortcut was mapped to idle.pyw instead of idle.bat. Everything running smoothly now

matplotlib.show() hangs into an infinite loop

Note: please dont mark it as duplicate, the previous question doesnt answer it completely.
This question has been answered partially in this link:
plt.show() hangs on OSX with Anaconda Python
However, there is no mention of where does the matplotlibrc resides to change the option. Also, specially when we are invoking the notebook using ipython notebook command, where can we use pythonw to overcome the issue?
Any help will be appreciated.
For me (W10 x64), the matplotlibrc resides in the folder
C:\Program Files\Anaconda\Lib\site-packages\matplotlib\mpl-data
It is just a text file you can edit with any editor to change the options.
What worked (but I'm really not understanding all of this) was the following config (line 38 and following):
backend : Qt4Agg
# If you are using the Qt4Agg backend, you can choose here
# to use the PyQt4 bindings or the newer PySide bindings to
# the underlying Qt4 toolkit.
#backend.qt4 : PyQt4 # PyQt4 | PySide
commenting this last line was necessary to finally have any curve plotted.
For your second question, I'm sorry I can't help at all.
I hope this will help you, good luck !

Read from stdin with monkeyrunner

How do I read from stdin with monkeyrunner? I tried the following code.
import sys
print("type something")
something = sys.stdin.readline()
print(something)
I also tried the following:
print("type something")
something = raw_input()
print(something)
In both cases the program prints "type something" but it does not respond after I type something. It seems i am making some silly mistake?
This seems to be a bug with Jython 2.5.3, the version that is included with MonkeyRunner. The issue says Mac OS X but I am able to reproduce on Ubuntu.
To fix it, you can download the Jython 2.5.4rc1 standalone Jar from the Jython website (download link) and copy it into the $SDK/tools/lib directory. Note that the Jython 2.7.0 standalone Jar will not work properly. You don't need to rename the new Jar, but you do need to (re)move the old jython-standalone-2.5.3.jar from the directory.
Another option (if you only need user input) is to use the input function in the MonkeyRunner class.

OMP warning when numpy 1.8.0 is packaged with py2exe

import numpy
When I packaged above one line script as a single executable window application using py2exe, I get following warnings upon launch.
OMP: Warning #178: Function GetModuleHandleEx failed:
OMP: System error #126: The specified module could not be found.
This warning happen only when I build as single executable (i.e., only when bundle_files=1). Here's my setup.py for this.
from distutils.core import setup
import py2exe
setup(
options = {'py2exe': {'bundle_files': 1}},
windows=['testnumpy.py'],
zipfile = None,
)
This problem started with numpy 1.8.0. When I revert back to 1.6.2, the warnings don't show up.
Usually a single executable packaged by py2exe will catch warnings and traceback and save them into a log file. But somehow these warnings are not captured and the app creates a console window to show warning. I want to suppress this additional console window to show up.
How can I fix this warning problem?
What I tried (nothing worked):
I tried this redirecting sys.stderr.
I searched github numpy source for openMP assuming the OMP stands for it as mentioned here. But, nothing useful came out.
I have copied libiomp5md.dll to the same folder as setup.py.
I tried filterwarnings:
I tried sys.excepthook.
As I wrote in the comment, installing numpy 1.8.1rc1 from sourceforge did fix the issue, although I don't really know the differences...
I had this issue with numpy 1.13.1+mkl and scipy 1.19.1. Reverting to numpy 1.8.1rc1 is not an acceptable solution.
I tracked this issue to the scipy.integrate subpackage. The warning message pops up when this package is imported. It seems that perhaps libraries that use MKL don't like being invoked from library.zip, which is where py2exe places packages when using bundle option 2.
The solution is to exclude scipy and numpy in the py2exe setup script and copy their entire package folders into the distribution directory and add that directory to the system path at the top of the main python script.

Py2Exe and MatPlotLib: Plot won't Appear

I have a working Python 2.6 code using matplotlib, and would like to get a working exe out of it. I am having problems getting this accomplished:
Initially I got an error for missing MSCVP90.dll, but I downloaded that and extracted the .dll to the working directory and that error went away.
I had some errors regarding a missing tkagg module, but I added that to the exceptions and edited the matplotlibrc file to default to WXAgg instead and that went away.
The exe runs normally, but at the end of the code it is supposed to display a plot, and it doesn't. The plot is the main goal of this program, so it would be good to have this.
Just running the python code brings the plot up just fine.
Can anyone offer any suggestions or insights?
Here's my setup.py:
from distutils.core import setup
import py2exe
import matplotlib
matplotlib.use('wxagg') # overrule configuration
import pylab
setup(
console=['test1.py'],
options={
'py2exe': {
'excludes': ['_gtkagg', '_tkagg', 'backend_tkagg'],
}
},
data_files=matplotlib.get_py2exe_datafiles(),
)
Thanks in advance!
Alright, I used pyinstaller and reverted the matplotlibrc file back to its original state where TkAgg was the default and everything works on my computer, but when I try to run it on another computer the plot still does not appear...
I can use pyinstaller to compile an exe out of a very simple matplotlib code, like:
from pylab import *
t = arange(0.0, 2.0, 0.01)
s = sin(2*pi*t)
plot(t, s, linewidth=1.0)
show()
But when I take that exe to another computer, it does not work.
Has anyone else had a similar issue? Any ideas?
Thanks
If the executable runs in your computer but doesn't work in another computer, the most likely problem is the lack of one or more of the required dlls that py2exe doesn't pack because license problems.
Very often these dlls are
gdiplus.dll
msvcp90.dll
Look for them in the computer where the exe works and copy them to the failing computer.
If the exe still doesn't work, check for other dll's. Py2exe gives the list of binary dependencies:
*** binary dependencies ***
Your executable(s) also depend on these dlls which are not included,
you may or may not need to distribute them.
Make sure you have the license if you distribute any of them, and
make sure you don't distribute files belonging to the operating system.
OLEAUT32.dll - C:\Windows\system32\OLEAUT32.dll
USER32.dll - C:\Windows\system32\USER32.dll
gdiplus.dll - gdiplus.dll
SHELL32.dll - C:\Windows\system32\SHELL32.dll
ole32.dll - C:\Windows\system32\ole32.dll
RPCRT4.dll - C:\Windows\system32\RPCRT4.dll
WSOCK32.dll - C:\Windows\system32\WSOCK32.dll
WINMM.dll - C:\Windows\system32\WINMM.dll
ADVAPI32.dll - C:\Windows\system32\ADVAPI32.dll
msvcrt.dll - C:\Windows\system32\msvcrt.dll
WS2_32.dll - C:\Windows\system32\WS2_32.dll
WINSPOOL.DRV - C:\Windows\system32\WINSPOOL.DRV
GDI32.dll - C:\Windows\system32\GDI32.dll
IMM32.dll - C:\Windows\system32\IMM32.dll
MSVCP90.dll - C:\Python26\programas\test\MSVCP90.dll
KERNEL32.dll - C:\Windows\system32\KERNEL32.dll
ntdll.dll - C:\Windows\system32\ntdll.dll
COMCTL32.dll - C:\Windows\system32\COMCTL32.dll
COMDLG32.dll - C:\Windows\system32\COMDLG32.dll
VERSION.dll - C:\Windows\system32\VERSION.dll
C:\Python26\programas\test>
Finally, I succesfully got a functional matplotlib program executable with py2exe. I only needed to add an 'includes' to setup.py and set WXAgg as the backend in matplotlib.rc (with Tk I got the same problem you described...). For it to work, I had to set WXAgg in the original matplotlib.rc (in the matplotlib/mpl-data folder). This is the one py2exe imports (not the one in the user's matplotlib configuration directory). To be sure check the .rc file in your dist folder.
from distutils.core import setup
import py2exe
import matplotlib
setup(
console=['test1.py'],
options={
'py2exe': {
'excludes': ['Tkconstants','Tkinter', 'tcl'],
'includes': ['matplotlib.backends.backend_wxagg'],
}
},
data_files=matplotlib.get_py2exe_datafiles(),
)
Today I lost one day of work with this, so...
The solution is to include "FileDialog" module explicity, because the "six" module uses it. Specifically, I solved my problem by including six, dateutil, FileDialog, matplotlib, pylab, matplotlib.backends.backend_tkagg and others.
Good Luck!