Page 1 of 1

Can't Save main.py

Posted: Fri Mar 24, 2017 2:18 pm
by tcontrada
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??

Re: Can't Save main.py

Posted: Fri Mar 24, 2017 3:59 pm
by dhylands
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?

Re: Can't Save main.py

Posted: Fri Mar 24, 2017 5:50 pm
by tcontrada
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...

Re: Can't Save main.py

Posted: Fri Mar 24, 2017 6:25 pm
by dhylands
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

Re: Can't Save main.py

Posted: Fri Mar 31, 2017 3:02 am
by starter111
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.

Re: Can't Save main.py

Posted: Fri Mar 31, 2017 3:30 am
by dhylands
I find its even easier to type:

Code: Select all

import yourpyfile

Re: Can't Save main.py

Posted: Sun Jun 10, 2018 5:51 pm
by KevinA
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.

Re: Can't Save main.py

Posted: Mon Jun 11, 2018 6:15 am
by pythoncoder
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.