Installing matplotlib-venn issues
I've tried installing matplotlib-venn on Pythonista using pip but I can't seem to get it to work.
Instead I get a 'No module named scipy.sparse._sparsetools' error when trying to run it.
When trying to install matplotlib-venn it also seems to try and install scipy as well, and I think it's done this incorrectly which is causing the problem.
Any advice on how to resolve this would be greatly appreciated.
It's not possible to install
scipyinto Pythonista yourself, because it requires large amounts of compiled code. (Apple's code signing requirements make it impossible to run any compiled code in Pythonista that doesn't come from Apple or the app developer.) This means that any libraries that depend on
scipyprobably can't be used either. If matplotlib-venn is a pure Python library, it will install successfully, but without its dependencies it won't work properly.
It might be possible to get the library to work if
scipyisn't used in many places in the library. You could try to edit the library source code (under site-packages) and comment out all
scipyimports, and see if the library still works. If you're lucky, you might be able to get the library at least partially working in Pythonista.
(Note: when you modify a library under site-packages, and you have already imported that library, your changes won't take effect right away because the imported module is cached. To fix this, you need to restart Pythonista, so that the library is reloaded properly.)
Looks like the only dependency isin _math.py, where it imports scipy.optimize.brentq, which is a root solver. It would not be very difficult to implement a numpy version of a root finder...
Thanks for the advice.
I had a bit of a play around with things but the fix is a bit beyond my skill level at the mo.
I keep running up against problems using Pythonista with these libraries (using matplotlib for animations doesn't seem to work either) so I think I'm going to give up on it for now and go back to using the PC.
@twotoed Hi, do not be discouraged, Pythonista is great, it is maintained by one person and for this reason can't be compared to a PC python environment (don't forgive the limits imposed by Apple about a lot of things...).
Anyway, as @dgelessus and @JonB suggested, a good way is to install in Pythonista the library you need, if it is impossible download and extract it in Pythonista site-package folder. Then find, inside the installed lib you want to use, all names of libraries not installable in Pythonista, like scipy, and comment them: you must find alternatives (in most cases you need to search internet for numerical recipes or for pure-python libs).
I know, in python world I'm also frustrated when I must download a big python lib even if I use only 3% of all features available in that lib.
About the lib matplotlib-venn, the only scipy request is, as @JonB pointed, a numerical root solver that is brentq, that you can replace with a similar one Pythonista has in built-in mpmath lib.
A solution using function findroot that you find in mpmath lib (already implemented in Pythonista) is:
- open _math.py in main folder of matplotlib-venn
- comment the scipy importing and adding in place of it: from mpmath import *
- where you find the command:
return brentq(lambda x: circle_intersection_area(r, R, x) - a, R - r, R + r)modify it by writing
return findroot(lambda x: circle_intersection_area(r, R, x) - a, R)where R is the average between 'R-r' and 'R+r' of the brentq function.
- save _math.py
Now you should be able to run the folowing test example that I found in Stackoverflow:
import matplotlib.pyplot as plt from matplotlib_venn import venn3, venn3_circles v = venn3(subsets=(1,1,0,1,0,0,0)) v.get_label_by_id('100').set_text('First') v.get_label_by_id('010').set_text('Second') v.get_label_by_id('001').set_text('Third') plt.title("Not a Venn diagram") plt.show()