Using MicroPython in Place of Python?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Locked
BinaryBen
Posts: 3
Joined: Sat Jul 02, 2016 2:52 pm

Using MicroPython in Place of Python?

Post by BinaryBen » Sat Jul 02, 2016 3:00 pm

Hi, I'm new to MicroPython (and Python at all really). I'm trying to understand, is it possible to use MicroPython in place of a "full" version of Python?

For example, I have a Raspberry Pi with piCore (a port of Tiny Core Linux) which includes MicroPython by default, because it is lightweight like the Linux distribution itself.

I am wondering about the possibility of compiling Vim with Python support for the board, but if it is also possible to use MicroPython in the place of regular Python - understanding that not all libraries (and functions?) will be available?

Same with compiling powerlines using MicroPython instead. Does MicroPython work like that? Any ideas on how to make/compile other apps with MicroPython instead of regular Python?

Please help a newbie?

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Using MicroPython in Place of Python?

Post by deshipu » Sat Jul 02, 2016 7:13 pm

You can use Micropython in place of Python in many cases, however, it's not a drop-in replacement for applications that embed Python. To use Micropython in their place, they would need to have an explicit support for that coded in them.

BinaryBen
Posts: 3
Joined: Sat Jul 02, 2016 2:52 pm

Re: Using MicroPython in Place of Python?

Post by BinaryBen » Sun Jul 03, 2016 10:48 am

Curious, so is this as simple as changing a few flags or paths to a particular "Python interpreter", or something like that? Or is this likely to require major rewrites of applications to support MicroPython?

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Using MicroPython in Place of Python?

Post by deshipu » Sun Jul 03, 2016 7:25 pm

It's a more of the "general rewrite" scale of change. The C functions you use to talk with the Python interpreter, and also what you can do with them, are different. It would be like adding support for yet another language.

torwag
Posts: 220
Joined: Fri Dec 13, 2013 9:25 am

Re: Using MicroPython in Place of Python?

Post by torwag » Mon Jul 04, 2016 7:46 am

Micropython is cpython 3 syntax compatible but not a cpython 3 replacement. Many things have left out to simply make micropython, well... micro.
That is, standard stuff like small scripts might run out of the box, however, when stuff gets more complex, you might face all kind of challenges. Also imho, cpython 3 is more extensive tested and error treatment is more complete. Thus, if there is no need to use micropython, I would go with cpython. On a RPi, there is far enough power to run python directly. I can see a use for micropython for far less powerfull boards with an OS, like some of the boards which use openwrt, or to embedd it as a simple scripting system in a program. However, RPis, BBBs and others are not really in need for micropython.

As a rule of thumb I would say if you count RAM and ROM in MB Cpython might do well. If you count in kB you might look into MicroPython. Sure there is an overlap, but there is also ongoing work to reduce the size and memory requirements of cpython.

markxr
Posts: 62
Joined: Wed Jun 01, 2016 3:41 pm

Re: Using MicroPython in Place of Python?

Post by markxr » Mon Jul 04, 2016 9:45 am

I wouldn't recommend using Micropython instead of Cpython if you can run Cpython.

There are plenty of opportunities to reduce the memory and disc footprint of CPython at compile-time, by disabling unused features. Even with almost everything disabled, it will still be much bigger than Micropython, but it is far more capable.

If you are, for instance, creating some kind of small embedded Linux distribution, as a virtualised appliance or for rescue or special-use purposes, I recommend initially trying to use CPython (use the latest version, of course!) with the options you don't need, disabled.

I think it's possible to run Linux with init=/myinit.py as a CPython script (although if you create subprocesses, you really need to ensure that your init reaps them correctly!). This is more difficult with Micropython, becuase the Unix port probably doesn't have all the functions you need to be a "proper" init-process.

Mark

BinaryBen
Posts: 3
Joined: Sat Jul 02, 2016 2:52 pm

Re: Using MicroPython in Place of Python?

Post by BinaryBen » Tue Jul 05, 2016 6:52 am

Thanks for the input everyone! :mrgreen:

In regards to using MicroPython instead of CPython, my hope is to use my RPi board/s to program other systems like an ESP8266/85 (and eventually ESP32) based systems/boards/projects/whatever. My thinking is that by using MicroPython on the system I am using to code with, as well as the target device, I can develop and code more efficiently?

Even more ideal, I'd also like to use Vim as much as possible for writing the code. I'd love to be able to include MicroPython support in Vim, and create a plugin that turns Vim into a micro IDE for developing MicroPython projects with. If it is faster or more lightweight, I'd be interested in seeing if some other Python based plugins can also work using MicroPython - hence the original question.

I believe I am essential hoping to create an appliance like distribution for developing and programming, especially for working with embedded systems. This is probably a very niche case though that only has appeal to a few people like me, who aren't always running around with a laptop or similar.

Also, as I mentioned, I am using a variant of Tiny Core Linux on the RPi, which allows me to run the programs from memory, something that I think provides a speed boost over the standard Raspbian/Debian based OS's. Obviously though, the more file system and programs I have loaded in RAM, the less RAM available for standard use. So in theory, there should be a benefit for using MicroPython when possible and only using CPython when I need the additional functions?

---

@torwag - you mentioned many things being left out. Is there a place to get a basic overview of what is left out, or even better a quick way to find what might be lacking in a given source code repo if trying to use MicroPython?

@markxr - see below, I'm probably not planning on having just MicroPython available on the system. I'd like it to be the default go to though if it makes sense (I.e., if it is faster/uses less memory/any other benefits). What you say makes a lot of sense though, and I will look into how far I can in making making CPython work on the RPi with TCL.

@EasyRider - I'm not a personal fan of the C.H.I.P. at all. That said, I do understand what everyone is saying in terms of when to use MicroPython, and that's probably not normally on an expensive board that has all the requirements for CPython ready to go :)

---

Also just for reference everyone, I expect I will have Python 2 and 3 (CPython?) available for use on the RPi along side MicroPython. I am not expecting to be able to replace it for everything, but would rather be very keen to use it in things I will likely use every day - especially if there are any speed or ram or disk benefits to be had on a semi-constrained system.

So if you have any further thoughts or comments, please send them my way! I'd love to have any sort of direction on where to start. I suspect I have probably made a lot of poor assumptions as well, please help? :lol:

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Using MicroPython in Place of Python?

Post by pfalcon » Tue Jul 05, 2016 8:34 am

Hi, I'm new to MicroPython (and Python at all really). I'm trying to understand, is it possible to use MicroPython in place of a "full" version of Python?
If you are new to Python at all, you would better use CPython (aka ' "full" version of Python') than an alternative implementation of Python, like PyPy, JPython, or MicroPython, or bunch of others. The reason is simple - if you use CPython, you need to consult only its documentation while you learn, if you use any other alternative, you will need to consult both the documentation of CPython (which is a reference Python implementation) and a documentation of a particular alternative, which if course not so comfortable when you just a novice and learn things.

This topic has otherwise become advertisement/questionable advise galore, so is closed.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

Locked