I have a number of Matlab functions and scripts which have been developed over a couple of years. I want to continue using these scripts, but can't afford MatLab. That's why I would like to transfer them to python. Is there an easy way to do this? I am a beginner in Python and I have Spyder 3.7 installed on my computer.
Thank you!
You can try Octave - an open source free Matlab equivalent.
If you can run your functions and scripts in Octave, then you can call them from within Python using oct2py package in Python.
Look e.g. here.
By that, you wouldn't have to translate any code into another language (like Python), which would mean you could introduce new bugs which then you have to debug etc etc ...
Related
In my program in need to reconstruct matlab code in python but not in very low level. The problem is that i got following lines of matlab
p = sobolset(problem_size, 'Skip', 1e4, 'Leap', 1e3);
p = scramble(p, 'MatousekAffineOwen');
rand0 = net(p, pop_size);
And I'm not able to reconstruct it on my own. Didn't find python functions in python libraries that would do exacly the same. So my question is if i could easly blend in this matlab code to python code or do someone have other idea how I can deal with it?
Your best bet here is probably to use either MATLAB Compiler SDK to generate a Python package from your MATLAB code or to use MATLAB Engine for Python.
If you are going to share this code with others that don't have a MATLAB installation or if you're running on a machine that doesn't have a MATLAB installation, you CANNOT use MATLAB Engine. Compiler SDK does require you to have that specific license though. If you are licensed through a university, you probably already have access to that license.
Short version:
Is it possible to create a standalone program that can be distributed to computers that don't have python installed, which writes a python script during runtime and executes it during or shortly after?
Long version:
A project I've been wanting to do for a while is to create a visual programming interface, that lets people use Machine Learning without needing to know python/keras/numpy syntax. Programs like lobe or rapidminer already do this, but they are all bound to their own interfaces and servers. What i would like to do is create a program that:
anyone can use without needing python/anaconda installed
allow the user to create visual scripts like in scratch or google-blocs
generates python code behind the scenes containing keras or tf code
is able to execute the script
is able to show the code to the user for:
educational purposes
allowing the user to use it as a base for a more complex program
Since the generation part would just need to create a text file almost any interface and language like python/java using Qt or C# / javascript using Unity, would qualify. I think that should definitely be doable, probably just very long, but that is not my largest concern.
The problem:
I have tried to search everywhere on the internet about things like standalone python programs which led me to for instance py2exe. Those kind of python-to-exe's work great, but they all require the script to be compiled on a machine containing a python environment. In my case i want to be able to generate a python script on the user's PC, and run it directly after from there.
The alternative
If this isn't possible i might just create the whole AI part myself, not using python nor libraries like keras or tensorflow, but in a unity game for instance. The downside to this would be that it exists already(like rapidminer), it would be less optimized/versatile/customizable and doesn't show what the "real" machine learning script would look.
If there are any other alternatives i would be happy to hear them
PS.
I have mostly Python & Keras, moderate Java and little Unity3D or web JS experience
I'm using Windows with anaconda
Distributing to linux/mac would be nice, but not required
maybe you should check the Orange Data Mining software, it's written in python and it has the same purpose as your project (https://orange.biolab.si/). On the other hand, some time ago I tried to compile my app that contains machine learning libraries but to date, I have not been able to achieve it. Instead, what I use is the WINPYTHON project, this is a portable Anaconda software that allows you to run projects on any PC without the need to install anything (https://winpython.github.io/).
Yes, it is possible!
I had the same requirement, so I wrote my visual programming language and IDE...
...that could generate an almost python-like script, and which is compiled natively inside the app, without the use of any external compilers or libraries.
My target architecture was mobile devices, but it also works on browsers via the unity plugin.
...and yes, that's correct, it runs natively on your phone or tablet in a simulated sandbox, with its own built-in IDE.
It's written in C#, and implemented in Unity3d
You can check it out at https://aiBoard.blog
..and see the videos at https://youtu.be/DIDgu9jrdLc
I'm helping my wife try and navigate IBM SPSS and python. She knows SPSS, and I kinda know python -- We might be able to work together. As it stands, I understand that I can call small snippets of python from within an SPSS syntax. While this is useful for looping and conditional branching based on data, it seems a little fuzzy to me. It almost feels like Inversion of Control, but not really.
I was wondering is it possible to have a python script, external to an spss syntax, that can still use the SPSS libraries in any meaningful way, or do I have to keep my scripts confined to the SPSS syntax and runtime?
Yes, you can run Statistics in external mode from a Python or R program. You might have to add the SPSS Python directory to your Python search path, but then just do
import spss
and run your Python code. The only thing you can't do is Viewer and user interface stuff, because there is no SPSS UI in that mode. By default, you will get output as text (which you can turn off when you get the hang of things). If you want better quality output, you can use OMS to capture output in a wide variety of formats.
Note that you need a compatible version of Python if you don't use the one installed with SPSS. That would be 2.7 for most Statistics versions. The Python installed with Statistics is not registered, but you can install a standard version from Python.org and just add the SPSS Python directory to the search path.
HTH
All my previous work (some big functions) are programmed by Matlab (some .m files). Now I get some robots of which the embedded functions are programmed by python. I want to apply my Matlab functions into the robots, but it will be very hard to recode the functions by python. I find two methods:
call matlab function in python script: it need the Matlab environment, but the robot is independent of my PC when it works. I can not install Matlab in the robot.
translate matlab to python. I installed numpy and scipy, and tried to configure the tool SMOP (under Win7), but there is always an import error: no module named readline.
Another possibility is to write an interface with C to call the .M function, and another interface of C called by python, and then link these two interfaces. But I have no idea with this work.
So I can not continue my work. Can you give me some advice? thank you.
How do I let my friends use my Python programs? They don't have python installed, but they can use command line programs. I don't have the skill to write GUI.
Let, say I am writing some calculus calculator, with a lot of custom modules and files. How do I share it?
You could use something like py2exe to convert your Python program into an executable.
another alternative you can try is Portable python.
You have the options presented thus far: Portable Python and Py2Exe. Either can be pretty good.
My suggestion: encourage your friends to install Python! As you know, it's free, and simple to install and download. If they want your application bad enough, installing Python will be a no-brainer.
In 2019 I have been using PyInstaller mostly, works very well for all of my Python scripts I wish to convert to a single runnable exe.
A less general, but lightweight and simple way of putting many Python files into 1 or 2 files (Python programs) is Fredrik Lundh's squeeze program. When you "squeeze" a bunch of Python programs and modules, you can often produce a single Python program. People still need Python to run it (but it's included in most Unix distributions, including Mac OS X), but you can easily distribute it, as your program and modules are all bunched up in a single file.
http://hackerboss.com/how-to-distribute-commercial-python-applications/ mentions using preinstalled, bundled, and frozen interpreters, but i suggest for speed and security, to compile using Shed Skin, Iron Python, Cython, or PyPy. The psyco module also helps with speed if your code is old.