Can't Save main.py

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
tcontrada
Posts: 5
Joined: Mon Feb 27, 2017 5:19 pm

Can't Save main.py

Post by tcontrada » Fri Mar 24, 2017 2:18 pm

I have had nothing but frustration with the pyboard, first the serial driver now this.

When I try to create a new main.py file I get an error saving the file to the pyboard drive "can't save file as it's open in another program".

Well, I don't have any other programs open which are related to this file... What's is causing this??

User avatar
dhylands
Posts: 2821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: Can't Save main.py

Post by dhylands » Fri Mar 24, 2017 3:59 pm

I've honestly never seen that error before.

Some additional information might be useful:
1 - You mention pyboard, so I'll assume that you're using the real pyboard (STM32F405)
2 - What host are you using (Windows, linux, Mac)
3 - How are you trying to copy the file?

tcontrada
Posts: 5
Joined: Mon Feb 27, 2017 5:19 pm

Re: Can't Save main.py

Post by tcontrada » Fri Mar 24, 2017 5:50 pm

Turns out I had to close the Windows File Explorer as well.

Basically these steps:
1. Open File Explorer and select pybflash drive.
2. Open main.py and edit file, new code, etc. and save.
3. Close Editor
4. From File Explorer Eject pybflash drive
5. Close File Explorer
6. Press Reset Button on pyb

Then repeat if editing the main.py file again...

User avatar
dhylands
Posts: 2821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: Can't Save main.py

Post by dhylands » Fri Mar 24, 2017 6:25 pm

For developing, I tend not to bother with main.py and instead put my code in some other file like foo.py and then from the REPL do:

Code: Select all

import foo
If that doesn't work, then I'll hit Control-D, copy the file, hit Control-D and redo the import.

Well, that's what I did before rshell anyways. Now I use rshell (running on my linux host) and I normally use the following:

Code: Select all

cp foo.py /flash; repl ~ import foo
then when things don't work, I hit Control-X, up arrow and repeat. rshell should work under windows, although it will most likely work better under cygwin.
https://github.com/dhylands/rshell

starter111
Posts: 14
Joined: Wed Mar 08, 2017 7:24 am

Re: Can't Save main.py

Post by starter111 » Fri Mar 31, 2017 3:02 am

always good save your code in your pc. I usually save the file to pc first and copy the file to byboard, after that just need to type execfile('yourpyfile.py') in your repl.

User avatar
dhylands
Posts: 2821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: Can't Save main.py

Post by dhylands » Fri Mar 31, 2017 3:30 am

I find its even easier to type:

Code: Select all

import yourpyfile

KevinA
Posts: 11
Joined: Mon Nov 09, 2015 11:17 pm

Re: Can't Save main.py

Post by KevinA » Sun Jun 10, 2018 5:51 pm

Finally! The import foo.py works with a Ctrl+C to kill the code. Edit on local PC drive then copy foo.py to the micropython drive and in putty terminal import foo.py runs the code without ejecting the drive and hitting reset!

The whole edit main.py burned some time as the editors really don't like the file system disappearing or whatever was going on, UltraEdit locked up, Note++ reacted badly and MU can't find the device or the COM port but at least MU can write the file and it works, sometimes.

User avatar
pythoncoder
Posts: 2806
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Can't Save main.py

Post by pythoncoder » Mon Jun 11, 2018 6:15 am

The feature whereby the Pyboard appears as a disk device in the PC's filesystem causes more problems than it solves (in my opinion). Experienced users tend to disable this by modifying boot.py to disable MSC mode:

Code: Select all

pyb.usb_mode('CDC')
Communication with the Pyboard is via Dave Hylands' rshell. Edit the Python code on the PC, then at the rshell prompt copy it to the Pyboard and run it:

Code: Select all

/home/adminpete> cp hello.py /sd
/home/adminpete> repl
Entering REPL. Use Control-X to exit.
>
MicroPython v1.9.4-118-g593a0be-dirty on 2018-06-10; PYBv1.1 with STM32F405RG
Type "help()" for more information.
>>> 
>>> import hello
Hello world.
>>>  
/home/adminpete> 
To get from the >>> prompt to the rshell (/home/adminpete> in my case) prompt you issue ctrl-X.

Working at a command prompt may present a learning curve but it's fast and utterly reliable.
Peter Hinch

Post Reply