使用python在web上部署matlab应用程序 [英] Deploying matlab app on the web using python

查看:214
本文介绍了使用python在web上部署matlab应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用python在web上部署一个matlab应用程序。有没有办法做到这一点。根据数学作品网站上的文档,我将应用程序转换为jar文件(java类)。有人可以指出我正确的方向去执行

解决方案

事实上,你的Matlab代码被打包成Jars可能不会帮助在这里,至少不是纯Python。



有几种方法可以使用Java编写的代码并将其公开给Python。



Jython



如果你愿意给Jython一个镜头,这可能是一个很简单的方法来为你的jar提供一个Django界面。



基本上你可以编写一个正常的Django应用程序,并且还可以使用Jython来与你的Jars一起工作。假设您没有绑定到CPython,这可能是两个世界中最好的。



Django-Jython



Java兼容性接口



在CPYTHON中以下项目将帮助您处理您的Jar文件中的代码:




  • JCC :创建一个包装Jar文件的Python扩展模块

  • JPype :提供一个用于运行JVM的API,并从Python调用该JVM中运行的代码。



单独的进程:



如果您有一个用Matlab编写的独立程序(真的是任何语言),可以将其作为Django应用程序的子进程执行。您可以在Django中查看一个简单的Web表单,允许您提交值作为此过程的输入,然后在您的视图(验证表单)后,您将执行以下操作:

  command =mymatlabprogram.exe%s%(arg1,)
process = subprocess.Popen(command.split())
stdout ,stderr = process.communicate()

假设你可以从stdout或错误消息中提取答案出来的stderr。您可以提供由该过程创建的图像等。一旦像这样的工作,您可以查看celeryd从您的网络应用程序中提取子处理内容。



优势使用单独的过程是您隔离您的Matlab代码中的错误,破坏您的Web应用程序和副作用。缺点是您必须序列化所有内容,并在客户端的浏览器和网络应用程序之间,Web应用程序和可执行文件之间进行多次复制,然后返回到客户端。


Hi I want to deploy a matlab application on the web using python. Is there a way to do it.I have converted my application into jar files (java classes) as per the documentation on math works site. Can someone point me in the right direction to go ahead

解决方案

The fact that your Matlab code is packaged up as Jars may not help that much here, at least not with pure Python.

There are a few ways you can take code written in Java and expose it to Python.

Jython

If you are willing to give Jython a shot this may be a really easy way to provide a Django interface to your jars.

Basically you'll get to write a normal Django App and also use Jython to work natively with your Jars. This could be the best of both worlds assuming you aren't tied to CPython.

Django-Jython

Java Compatibility Interfaces

On CPYTHON either of the following projects will help you work with the code in your Jar files:

  • JCC: Create a Python extension module that wraps your Jar file
  • JPype: Provides an API for running the JVM and calling into code running in that JVM from Python.

Separate Process:

If you have a standalone program written in Matlab (really any language) you could execute it as a child process of your Django application. You'd look into a simple web form in Django that allowed you to submit values to be inputs to this process and then in your view (after validating the form) you'd do something like:

command = "mymatlabprogram.exe %s"%(arg1,)
process = subprocess.Popen(command.split())
stdout, stderr = process.communicate()

Assuming that worked you could pull answers out of stdout or error messages out of stderr. You could serve an image created by that process, etc. Once something like this is working you could look into celeryd to extract the subprocess stuff from your web app.

The advantage of working with a separate process is that you isolate bugs in your Matlab code from breaking your web application and vice versus. The disadvantage is you have to serialize everything and work with multiple times between the client's browser and your web app, between the web app and the executable, and back to the client.

这篇关于使用python在web上部署matlab应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆