How to use external modules in MicroPython on micro:bit from VSCode - visual-studio-code

I’m new to both micro:bit and MicroPython (or Python in general) - but I want to have it all running in VSCode. I grabbed this extension which was really smooth working with.
My problem now is that I want to leverage external modules, for things like the NeoPixels and also the bit:bot stuff, but I don’t know how to actually get that working. The NeoPixel tutorial is straight forward, but there is no mention on how to add the module.
I tried adding them with pip - but that won’t make them end up on the device. I’ve also tried this extension - hoping it would do some more magic in getting it onto the device.
Is this doable? Or would I have to revert do the online editors?

The micro:bit is a very constrained environment and will not run Python only MicroPYthon. MicroPython was designed to work under the constrained conditions of a microcontroller. As a result MicroPython does not come with the full Python standard library and only includes a small subset of the Python standard library.
For MicroPython to run on the micro:bit there needs to be the MicroPython hex file and any Python code that you have written, with main.py being the entry point.
The VS Code Extensions you linked to use uFlash to copy from your machine to the micro:bit the hex file and any Python files you have written.
To use the neopixel module it should be as straight forward as import neopixel as it is part of the standard BBC micro:bit MicroPython.
For BitBot, it only uses the standard micro:bit MicroPython library so I'm not sure what you are looking to import.
You can create a module by putting the code in .py file and referencing it in your main.py file. You do this by using an import statement that calls the file or specific parts of it.
MicroPython does have the concept of upip but I am not aware of that being available on micro:bit.

Related

Missing Python file for models using pyCommunicator

My experience with Python is limited, but I just started looking at the new Python models included AnyLogic's examples. I am looking at the 1st one Passing Data Types. The model runs correctly with the set, modify and get functions working as expected. My question is there a python file somewhere that the communicator is working with? I only see the .alp file in the folder.
Thanks
I'm also beginning to use this, but as I understand, the idea of the python helper here (among other things) is that you can run python commands with Anylogic, so you actually don't need a python file. Nevertheless it uses python installed in your computer to run the scripts, if you don't have python installed, your model won't work.

Python in EV3 - What modules are installed?

I have specific question. I have lego EV3 and i installed Micropython. But i want import turtle, tkinter and other modules and they aren't in micropython. But time module working.Do someone know what modules are in ev3 micropython? Thanks for answer.
welcome to Stackoverflow. MicroPython is very specific to the board it has been ported to run on. There are both standard libraries and hardware specific libraries in your MicroPython port and then open-source libraries you can install. I bet MOST of the Python and MicroPython specific libraries will be in your image. More on Libraries here: http://docs.micropython.org/en/latest/library/index.html
I did not see any online documentation for Lego's MicroPython version online. If you can find it, it may have this information. If so, please post back the link in the comments.
In the absence of good documentation you can discover what is available using help().
From the link above...
On some ports you are able to discover the available, built-in libraries that can be imported by entering the following at the REPL:
help('modules')
Your other question is will every Python library work on MicroPython? No. Most will not. You can search for libraries which will work on https://libraries.io. Just be sure to use the filters to narrow the results to MicroPython libraries.
If you are in fact running micropython, you're probably not going to find any of those modules. It has "micro" in the name of a reason; while it supports a great deal of Python 3 syntax, it is not fully compatible with C python and most modules not written explicitly for micropython won't work.
You can get a list of built-in modules by running help("modules"), and you can see any modules installed on the filesystem using os.listdir().

How to deploy application which uses pybind11?

I know pybind11 provides a way to call Python from C++. My question is, how can I distribute the application? For example, does user still need to install Python and Python packages on their machine?
I wish that if I use pybind11 , I can just put used Python scripts under my app folder, and called from C++. User doesn't need to install Python at all on his machine. Can pybind11 achieve this goal? Or can Python/C API or Boost.Python do that?
No, you'll have to install python. All of those packages, and ones like it, are language bindings between C++ and Python. Say you'd like to use a Python script in your C++ project and so you made some bindings for the Python script using Pybind11. When you run your C++ code, it'll use parts of the Python script which will be run in Python. What Pybind11 allows you to do is translate the input to and the output from the Python script, it does not reimplement it.

Library libusb 1.0.9 on Raspberry Pi

I am having a problem with compilation of my Java file.
I want to use the libusb-1.0.9 library, but the problem is that it cannot find the symbols, like LibUsbException, LibUsb.bulkTransfer, etc. The code is written in the nano text editor, and I have no idea how to implement this library to my code.

How can I import a .PYD module in IronPython?

I'm trying to use a python package from IronPython.
Everything works fine if I import regular python modules.
But when I try to do the following:
import win32ui
I get:
No module named win32ui
I've hunted through the code in IronPython.Runtime.Importer and there's no mention of .pyd
Anyone know a way around this?
You can check out IronClad which is working to provide this support. It may or may not work w/ your PYD of choice.
A .pyd file is a DLL. So unless IronPython (which is written in .net) can correctly load C DLLs written for CPython, you might be out of luck.
Update
In fact, according to the IronPython FAQ, you are unfortunately unable to import .pyd files:
Q: How do I build and call into PYD libraries?
A: IronPython does not support using PYDs built for CPython since they
leverage implementation details of CPython. You can get a similar
effect for new "PYD"s you would like to implement by writing them in C#
or VB and building a DLL for .NET.