EsPy/Thonny IDE and local import

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Listian
Posts: 6
Joined: Tue Apr 14, 2020 8:05 pm

EsPy/Thonny IDE and local import

Post by Listian » Tue Apr 21, 2020 1:20 am

Hello!

Using EsPy or Thonny IDE it is possible to import modules from a computer disk during debugging, but not from Flash?

Because it gives an error that the module was not found :(

ImportError: no module named 'bla-bla'

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: EsPy/Thonny IDE and local import

Post by jimmo » Tue Apr 21, 2020 3:18 am

Listian wrote:
Tue Apr 21, 2020 1:20 am
Using EsPy or Thonny IDE it is possible to import modules from a computer disk during debugging, but not from Flash?
If I understand correctly, you want to have the MicroPython device access the host PC's filesystem? The simple answer is "not really" but... here are some options that might be interesting (that don't involve Thonny or EsPy).

rshell -- has an "rsync" mode that just lets you syncronise the device with your filesystem quickly and easily. This seems to be really popular.

https://github.com/nickzoic/mpy-utils has a FUSE filesystem that makes it possible to "mount" the ESP's filesystem as if it were a disk on your PC (which makes the ESP behave a bit more like the Pyboard).

https://github.com/micropython/micropython/pull/3034 is a not-released but very cool variant on pyboard.py (see http://docs.micropython.org/en/latest/r ... rd.py.html ) which pretty much does exactly what you're asking -- it makes the ESP see your PC's filesystem. I use this quite often, it's really convenient.

Listian
Posts: 6
Joined: Tue Apr 14, 2020 8:05 pm

Re: EsPy/Thonny IDE and local import

Post by Listian » Tue Apr 21, 2020 2:41 pm

jimmo wrote:
Tue Apr 21, 2020 3:18 am
If I understand correctly, you want to have the MicroPython device access the host PC's filesystem? The simple answer is "not really" but... here are some options that might be interesting (that don't involve Thonny or EsPy).

Not this way)

As I understand the development environment send commands to esp through the com-port.

It would be logical to add functionality that, when importing a module, checked for its presence on esp, and if it wasn’t there, it would start from a local directory.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: EsPy/Thonny IDE and local import

Post by jimmo » Wed Apr 22, 2020 3:02 am

Listian wrote:
Tue Apr 21, 2020 2:41 pm
Not this way)

As I understand the development environment send commands to esp through the com-port.

It would be logical to add functionality that, when importing a module, checked for its presence on esp, and if it wasn’t there, it would start from a local directory.
Sorry I'm not sure what you mean then... where is "a local directory" if not the host PC?

Or are you saying that you want Thonny (or equivalent) to automatically detect that the code contains an "import foo" line and also copy across foo.py while copying (e.g.) main.py?

Listian
Posts: 6
Joined: Tue Apr 14, 2020 8:05 pm

Re: EsPy/Thonny IDE and local import

Post by Listian » Wed Apr 22, 2020 7:25 am

jimmo wrote:
Wed Apr 22, 2020 3:02 am
Or are you saying that you want Thonny (or equivalent) to automatically detect that the code contains an "import foo" line and also copy across foo.py while copying (e.g.) main.py?

Yep) Just do not need to copy anything.
Thonny should insert the foo.py file from the computer and execute it, like the main script.

We look "import %module_name%", checked its presence on flash memory.
If it is on flash memory, then esp executes it. If not, Thonny does it.

I do not see anything complicated in implementation.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: EsPy/Thonny IDE and local import

Post by jimmo » Wed Apr 22, 2020 11:27 am

Listian wrote:
Wed Apr 22, 2020 7:25 am
We look "import %module_name%", checked its presence on flash memory.
If it is on flash memory, then esp executes it. If not, Thonny does it.

I do not see anything complicated in implementation.
It's a bit complicated because it's not just a matter of executing the file -- it needs to be done in a way that it still looks like a module.

But this is more of a Thonny question, might be worth getting in touch with Aivar (@aivarannamaa on this forum) or raising a feature request on https://github.com/thonny/thonny/issues

Post Reply