Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

how to precompile a .py file to a .mpy file Windows 10
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

how to precompile a .py file to a .mpy file Windows 10

by Assemble_In_Mexico on Thu Jun 25, 2020 12:25 pm

Using Windows 10.

I've developed a nifty new project, installed Python and the mpy-cross module, slain dragons and successfully battled with memory issues yet I cannot compile a .py to an .mpy file. Could someone so kindly post some tips?

- The project usage section (https://pypi.org/project/mpy-cross) doesn't work for me such as within a command prompt using
Code: Select all | TOGGLE FULL SIZE
python -m mpy_cross filename.py

- The github project (MicroPython cross compiler) talks only about a Unix system.
- CircuitPython releases (https://forums.adafruit.com/viewtopic.php?f=60&t=145860) state that pre-built mpy-cross executables are available above for MacOS, Windows, Ubuntu, and Raspbian, yet I don't see anything useable.

I'm embarresed I can't see how to do this simple task and only hope that learning how here may be of help to others. Thanks in advance.

Assemble_In_Mexico
 
Posts: 18
Joined: Sun May 03, 2020 10:50 am

Re: how to precompile a .py file to a .mpy file Windows 10

by mikeysklar on Thu Jun 25, 2020 1:06 pm

Hello,

You will need to install a Windows subsystem for Linux (WSL) so that you can build mpy-cross on your Win10 box.

https://learn.adafruit.com/building-cir ... -for-linux

Once you have the WSL up and running Ubuntu you can build the mpy-cross compiler included with the github repo:
https://learn.adafruit.com/building-cir ... cuitpython

mikeysklar
 
Posts: 1644
Joined: Mon Aug 01, 2016 8:10 pm

Re: how to precompile a .py file to a .mpy file Windows 10

by Assemble_In_Mexico on Fri Jun 26, 2020 1:59 pm

Wonderful. I was missing the big picture, that of using WSL. Thank you so much for the tip mikeysklar!

Working from the posted instructions I have installed Ubuntu through WSL, cloned CircuitPython, installed and updated all submodules, then built mpy-cross. I should be there yet I am still missing something not specified anywhere in the Adafruit learning section, that of how to make the .mpy file. I see some instruction here if it's helpful --> https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/creating-a-library#mpy-2982472-11

Suppose I have a single .py file named library.py located in the /circuitpython/mpy-cross directory. With an Ubuntu command prompt how would one make the .mpy file?

Assemble_In_Mexico
 
Posts: 18
Joined: Sun May 03, 2020 10:50 am

Re: how to precompile a .py file to a .mpy file Windows 10

by Assemble_In_Mexico on Tue Jun 30, 2020 1:51 pm

Anybody know what Ubuntu command(s) to issue to create a .mpy file?

Assemble_In_Mexico
 
Posts: 18
Joined: Sun May 03, 2020 10:50 am

Re: how to precompile a .py file to a .mpy file Windows 10

by mikeysklar on Tue Jun 30, 2020 1:58 pm

Once you have a working mpy-cross compile installed the command to convert your .py to an .mpy is:

Code: Select all | TOGGLE FULL SIZE
mpy-cross example.py


https://learn.adafruit.com/creating-and ... spberry-pi

mikeysklar
 
Posts: 1644
Joined: Mon Aug 01, 2016 8:10 pm

Re: how to precompile a .py file to a .mpy file Windows 10

by Assemble_In_Mexico on Tue Jun 30, 2020 2:21 pm

Thanks again for the tip compadre. I feel I’m close yet must be missing something stupidly simple.

If I go to the /circuitpython directory and issue 'make -C mpy-cross' it succeeds with
Code: Select all | TOGGLE FULL SIZE
text    data     bss     dec     hex filename
216113   20832     976  237921   3a161 mpy-cross


I then show I have a file say, library.py in the mpy-cross directory, and therein issue mpy-cross library.py yet I am getting an mpy-cross: command not found error.

Assemble_In_Mexico
 
Posts: 18
Joined: Sun May 03, 2020 10:50 am

Re: how to precompile a .py file to a .mpy file Windows 10

by jerryn on Tue Jun 30, 2020 2:25 pm

if this is Ubuntu and the mpy-cross is in the working subdirectory, try
Code: Select all | TOGGLE FULL SIZE
./mpy-cross filename.py


otherwise provide the full path the mpy-cross:
Code: Select all | TOGGLE FULL SIZE
/path/to/mpy-cross filename.py

jerryn
 
Posts: 1291
Joined: Sat Sep 14, 2013 9:05 am

Re: how to precompile a .py file to a .mpy file Windows 10

by Assemble_In_Mexico on Tue Jun 30, 2020 2:38 pm

Still no dice. My mpy-cross directory is that provided within circuitpython, so I issue

Code: Select all | TOGGLE FULL SIZE
/home/<username>/circuitpython/mpy-cross library.py


and get -bash: /home/<username>/circuitpython/mpy-cross: Is a directory

Assemble_In_Mexico
 
Posts: 18
Joined: Sun May 03, 2020 10:50 am

Re: how to precompile a .py file to a .mpy file Windows 10

by mikeysklar on Tue Jun 30, 2020 3:00 pm

You have to compile and install mpy-cross.


Code: Select all | TOGGLE FULL SIZE
 git clone https://github.com/adafruit/circuitpython.git
cd circuitpython/mpy-cross
make
./mpy-cross example/adafruit_example.py


details here:

https://learn.adafruit.com/creating-and ... y?view=all

mikeysklar
 
Posts: 1644
Joined: Mon Aug 01, 2016 8:10 pm

Re: how to precompile a .py file to a .mpy file Windows 10

by Assemble_In_Mexico on Tue Jun 30, 2020 3:22 pm

Success! I am in your debt mikeysklar. I had everything installed right, it was a matter of being in the right directory and issuing the command for the right directory. All good here; let's hope this may be of help to another poor wanderer as it has been for me.

Assemble_In_Mexico
 
Posts: 18
Joined: Sun May 03, 2020 10:50 am

Re: how to precompile a .py file to a .mpy file Windows 10

by mikeysklar on Tue Jun 30, 2020 4:29 pm

well done, Sir!

mikeysklar
 
Posts: 1644
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.