Transcrypt icon indicating copy to clipboard operation
Transcrypt copied to clipboard

Can't import matplotlib

Open drscotthawley opened this issue 5 years ago • 4 comments

Hi. Thanks for sharing this tool. I'm sure I'm doing something wrong, but haven't been able to figure out from the docs what that might be.
I was able to run the hello example just fine, but a simple scientific plot fails on line 3. I haven't seen any notes in the documenation about potential matplotlib problems, and haven't noticed other issues or StackOverflow posts about people having trouble with matplotlib, so I assume it's something I'm doing.
Could someone offer any feedback? Thanks. (I will say that I can import matplotlib in my python installation without problems!)

My code reads:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation, rc
#(...and then it goes on...)

Running transcrypt yields

$ transcrypt -b wave.py 

Transcrypt (TM) Python to JavaScript Small Sane Subset Transpiler Version 3.7.16
Copyright (C) Geatec Engineering. License: Apache 2.0


Saving target code in: /tmp/wave/__target__/org.transcrypt.__runtime__.js
Saving minified target code in: /tmp/wave/__target__/org.transcrypt.__runtime__.js

Error while compiling (offending file last):
	File '/tmp/wave/wave.py', line 3, at import of:
	File '/home/myusername/anaconda3/envs/spnet/lib/python3.7/site-packages/matplotlib/animation.py', line 3, at import of:
	File 'matplotlib', line 1586, namely:
	
	Can't import from module 'matplotlib'

Aborted

drscotthawley avatar Nov 30 '20 07:11 drscotthawley

Since Transcrypt is converting the Python code to a JavaScript equivalent, most 3rd party Python libraries are not supported unless they are pure Python (including dependencies), and do not rely on any C libraries. NumPy is an exception thanks to the Numscrypt project.

If you are trying to plot Python data in a browser, have you looked into Dash yet?

JennaSys avatar Nov 30 '20 18:11 JennaSys

Thanks for clarifying @JennaSys. I'm one of those people who only uses the "Python Scientific Stack", who often operates as if matplotlib is an integral part of Python, which is obviously untrue.

I'm familiar with Plot.ly products but was under the mistaken impression that they couldn't work offline. I'll look into Dash. (I just took a "Dash" course but it was a different Dash!) Seems like Dash can be bundled & run offline, so that's encouraging. Thanks!

Another alternative, I spent some time last night with Pyodide and got a rough version of my simulation idea working.

Feel free to close this.

drscotthawley avatar Nov 30 '20 18:11 drscotthawley

An update if it helps, since you are on the data science side of things, you might be interested in the IDOM project that takes an encapsulated though more constrained approach to what Transcrypt does (let's you create front-end web applications with Python).

JennaSys avatar Apr 22 '21 21:04 JennaSys

Maybe it's also worthwhile to take a look at:

http://www.transcrypt.org/live/transcrypt/demos/plotly_demo/plotly_demo.html

JdeH avatar Jun 01 '21 10:06 JdeH

Closing this issue due to no further comments.

JennaSys avatar Apr 23 '23 08:04 JennaSys