[Microbit-Python] Can't get MU to run on MACbookAir

Radomir Dopieralski microbit at sheep.art.pl
Wed Aug 3 10:11:44 EDT 2016


You can install Python om your mac or pc, and use that to learn to
program, but the programs that are written for the micro:bit will not
work. The language is the same, but the hardware it runs on offers
completely different features, and the libraries are different too. You
also use different tools on both of them -- the Mu editor on the
micro:bit, some programming editor or IDE and a python interpreter on
your PC.

You could compare it to natural languages: both literary critics and
mathematicians may be speaking English, but the vocabulary they use,
and the ideas they are trying to express are completely different, and
they would still not understand each other.

It's similar with Python on the PC and on the micro:bit -- the syntax
is the same, but the commands you have available are different --
because the devices are very different. So a program written for one
will not work on the other.

As for the "from microbit import *" thing -- that imports everything
that is available in the microbit module to the local namespace.
However, the Mu editor doesn't know what is available in the "microbit"
module (because it doesn't have access to it, as it can't run on your
computer, only on the micro:bit), and so it's unable to determine what
names are actually getting imported there. Since it doesn't know what
names are available, it can't further help you by spotting misspellings
or use of undefined names. That's what this warning is about. If you
want to get rid of it, you can explicitly import the names you need,
for instance "from microbit import pin0, pin1".

I hope that helps.


On Wed, 3 Aug 2016 15:55:07 +0200
Robert Humphrey <humphrey.robert at orange.fr> wrote:

> Yes,  sort of.   The Microbit has 32K memory.  Are you saying that a
> Python 3.6  19Mb zip file expands into 32K on the Microbit ??  That
> can’t be right - can it?
> 
> 
> Regarding Python 3.6 on a MAC.  I think you are saying that I should
> not have Python 3.6 on the MAC at all,  but MU on the MAC My Microbit
> has not arrived yet - I am just trying to understand Python (or
> something) pre arrival.  MUST I always have the microbit attached to
> the MAC to write code? If not then why when I write a line of code
> 
> from microbit import *  do I get the message IMPORT error  ‘No module
> named microbit’  Please see the attached screen shot on last E-mail.
> If I use the web based interactive version, my Python code doesn’t
> seem to have errors
> 
> As regards MU,  the screen shot shows “errors" on every line or are
> these some form of helpful comments?  Yes,  it does produce a .hex
> file (which has data in it).  
> 
> What is syntactically incorrect with the statement:-
> from microbit import *  
> 
> When I click the CHECK button, I get
>  ‘ from microbit import * ‘  used; unable to detect undefined names
> [In English we would understand that ‘If you say words I don’t
> understand, I can’t help you’]
> 
> Please
> Bear with this old duffer - remember that in my day,  hard drives
> were only 25Mb, dates were held as compressed ASCII 5 byte strings
> (years ran from 0-9 and A-Z), Lowercase and fonts had not arrived and
> TELEX was new and FAX hadn’t arrived.  Input was by paper tape or
> punched card and VDUs - (Screens to you) were for the computer
> operator. ROM was made from diode arrays and memory was magnetic
> core.  My first home computer has 256 bytes of data and Binary had 3
> states - Off, On  and don’t know (Voltage region between -0.3 to +0.3
> volts) and programmed in Hex machine code.
> 
> Thanks    Bob
> 
> 
> 
> 
> 
> > On 03 Aug 2016, at 13:12, Nicholas H.Tollervey <ntoll at ntoll.org>
> > wrote:
> > 
> > Hi Bob,
> > 
> > From the screenshots, it appears that Mu is working fine on your
> > Macbook. I'm trying to work out what it is that *isn't* working for
> > you.
> > 
> > Please bear with me if any of the following is obvious ~ I just
> > want to make sure you've set yourself up properly.
> > 
> > 1) Mu is working.
> > 2) Plug in a micro:bit device to your Macbook via USB.
> > 3) Click on the flash button and your script (in the Mu editor)
> > will be transferred (flashed) onto the micro:bit (should take
> > around 6 seconds). If there are any errors they'll scroll across
> > the micro:bit's display. 4) Click on the REPL button to get access
> > to the interactive prompt for the version of Python running on the
> > micro:bit.
> > 
> > You don't need to install Python 3.6 onto your Macbook - you should
> > be using the version of Python *on* the actual device itself. For
> > this to work you flash the device with the MicroPython runtime as I
> > described in step 3 above. Following that, you get access to the
> > Python prompt by clicking the REPL button.
> > 
> > Does this make sense?
> > 
> > Best of luck,
> > 
> > N.
> > 
> > On 02/08/16 16:35, Robert Humphrey wrote:
> >> Thanks for the response.  I find it hard work trying to install
> >> Micro Python, and thanks for bearing with me.  The attached screen
> >> shot is typical. It appears that there in’t a library to import.
> >> 
> >> I followed your link via Pep-8, installed Python 3.6,  installed
> >> Active tcl 8.6. Ran Python 3.6 and get errors.   I re-tried MU and
> >> again it appears that there are no libraries to import. Is there a
> >> simple way to get all this working as I can get Python to work
> >> interactively from the net at W3. microbit.Pythonanywhere.com
> >> <http://microbit.pythonanywhere.com/>
> >> <http://microbit.pythonanywhere.com
> >> <http://microbit.pythonanywhere.com/>>,  but no luck locally. Bob
> >> 
> >> 
> >> 
> >>> ote:
> >>> 
> >>> On 02/08/16 13:37, Robert Humphrey wrote:
> >>>> I have installed MU from GitHub latest  MU-3  30/07/2016  but it
> >>>> errors out on every statement.  What haven’t I loaded?
> >>>> 
> >>>> Op Sys  OSX  El Capitaine
> >>>> 
> >>>> Example code:-
> >>>> 
> >>>> 
> >>>> 
> >>>> _______________________________________________
> >>>> Microbit mailing list
> >>>> Microbit at python.org <mailto:Microbit at python.org>
> >>>> <mailto:Microbit at python.org <mailto:Microbit at python.org>>
> >>>> https://mail.python.org/mailman/listinfo/microbit
> >>>> 
> >>> 
> >>> Hi Robert,
> >>> 
> >>> Thanks for the feedback.
> >>> 
> >>> In future, please just attach the PNG image file rather than
> >>> sticking the screen shot in a PDF - it's just simpler and I don't
> >>> have to twist my neck to see what you're up to (I sprained it
> >>> trampolining over the weekend). :-)
> >>> 
> >>> So, I'm trying to work out what exactly you mean. Do you mean
> >>> that Mu has an error in it and crashes OR that Mu is reporting
> >>> errors for every line in your code? Looking at your screenshot, I
> >>> believe you're reporting the latter.
> >>> 
> >>> If so, these are not errors!
> >>> 
> >>> Rather, they are code quality feedback annotations. Your code
> >>> probably will still work, but it has stylistic problems. For
> >>> example, I can see from lines 5-8 you use a comment "#" without
> >>> following it with a space (to aid readability). If you click on
> >>> the red arrow next to each line a little post-it note will appear
> >>> to explain why the line has been flagged.
> >>> 
> >>> Such code quality checking is advisory! Unless you get syntax
> >>> errors your code will run (although it may still contain bugs
> >>> because it doesn't work as you expect).
> >>> 
> >>> If you're interested in the conventions Mu uses for checking the
> >>> quality of your code you should read up on PEP-8 - the style
> >>> guide for Python programming (it's like the style guide
> >>> newspapers use to guide their journalists in writing in an
> >>> idiomatic and "house" style).
> >>> 
> >>> https://www.python.org/dev/peps/pep-0008/
> >>> 
> >>> PEP-8 was written by Python's creator Guido van Rossum and a
> >>> couple of other collaborators (including Nick Coghlan, who may be
> >>> subscribed to this list). It's their vision of well written,
> >>> idiomatic Python. Many Python programmers, myself included, use
> >>> it for guidance when writing code.
> >>> 
> >>> You are free to ignore it though. As PEP-8 itself says, "a foolish
> >>> consistency is the hobgoblin of little minds".
> >>> 
> >>> :-)
> >>> 
> >>> Hope this helps, and more than happy to answer any questions you
> >>> may have.
> >>> 
> >>> N.
> >>> 
> >>> _______________________________________________
> >>> Microbit mailing list
> >>> Microbit at python.org
> >>> https://mail.python.org/mailman/listinfo/microbit
> >> 
> >> 
> >> 
> >> _______________________________________________
> >> Microbit mailing list
> >> Microbit at python.org
> >> https://mail.python.org/mailman/listinfo/microbit
> >> 
> > 
> > 
> > _______________________________________________
> > Microbit mailing list
> > Microbit at python.org <mailto:Microbit at python.org>
> > https://mail.python.org/mailman/listinfo/microbit
> > <https://mail.python.org/mailman/listinfo/microbit>



-- 
Radomir Dopieralski

-- 
Radomir Dopieralski


More information about the Microbit mailing list