I want to use numpy in brython. But I do not know how to import extra modules in brython. If you have similar experience or question, please tell me way to solve
-
2https://brython.info/static_doc/en/import.html – Robert Harvey Aug 16 '19 at 00:51
-
Does this answer your question? [How to import library using Brython](https://stackoverflow.com/questions/40001634/how-to-import-library-using-brython) – Karl Knechtel Feb 11 '23 at 20:16
1 Answers
You can't. Brython is a transpiler from a Python-like syntax to Javascript code. While it holds good conformance to latest Python 3 syntax, and amazing compatibility, it does not have any features to support running binary code.
And numpy, along with a lot of third and first party Python libraries is compiled from C and other languages to native CPU code. There is no support, no way, and not even a roadmap, or prevision of prevision to allow that.
It may be possible to develop Brython front end apps that use those libraries running on the backend, though, performing all calculations on the server side, and just passing serialized data to the brython counterpart. One would habe to manually write this, though (and it might be possible to use a pure-python striped down version of numpy arrays just for deserializing, displaying, and submitting data to the backend)

- 99,910
- 10
- 151
- 209
-
thanks to answer the question. But I found this page. Acoording to this page, I think that I can use python library in brython. Do you know anything about this? http://brython.info/static_doc/en/options.html – Chihiro Nakatani Aug 19 '19 at 02:21
-
1no. it is just as I said in the answer. if a library has any native code, it can't run under brython, just like a car can't fly. If it is pure Python and use no filesystem or network access (nor depends on a module that does), it can likely run. – jsbueno Aug 19 '19 at 03:25
-
thanks fast answer. I understood your saying. I want to make web site to run machine learning or deep learning by python. According your answer, I think brython is not suitable to do it. If you have a idea to do it, please tell me. I want to do it in client side. – Chihiro Nakatani Aug 19 '19 at 03:53
-
1@ChihiroNakatani To do it client-side, either use a javascript machine learning framework, or if you really want to do it with Python you can try Pyodide, but it's still very experimental. The easiest is simply to program a dashboard using Panel or Streamit, and then run an heroku server from your github account, this will run the machine learning on a server but it will look like it's client-side thanks to the dashboard. – gaborous Apr 10 '20 at 16:42