Compile python script for Connectport X2 / X4 ?

Is there a way to compile a python script for the X2/X4 that is also using zigbee.py ? Attempting to compile locally obviously fails as zigbee.py isn’t available.

Is there a way to do this ? Can I do it on the connectport directly, and then copy the file back to a pc so that I can upload it to other connectports ?

thanks.

Can you tell us what you have tried? The byte-compilation process doesn’t actually perform any execution of the code inside a module, so you should be able to compile anything that’s syntactically valid just fine.

What I’ve typically done is use the standard library ‘compileall’ script to bytecompile things

python2.4 -m compileall .

Note the period at the end, that specifies the current directory, and the use of python2.4 to ensure that I’m using the correct version of Python for the gateway. This will leave new .pyc files in the directory for each python file.

Hi justmark,

You can use the py_compile standard module to byte-compile your code without running it (eg, without importing zigbee.py). Just make sure you are performing the compile operations with a compatible interpreter version with the target device.

Most ConnectPort X devices will use 2.4.x (where any 2.4 python interpreter is compatible). To verify the version of the interpreter, both on the gateway and on the PC performing the compile operation, you can start the python interpreter by calling ‘python’ and it reports the version string automatically.

Hope this helps,
Max

Thanks for the quick replies.

I had tried the suggestions on the link provided by Shahrj1988 prior to posting, but it had complained that one of the import files (zigbee.py) wasn’t available. I’ll try that again.

I’ll also try out your suggestion, DigiGuy42.

Thanks.

Max,

Tried this out. I made sure that I had 2.4.3 loaded onto my Mac, and followed your suggestion. It generated the .pyc file, which I then transferred to my Connectport.

Upon running it there, I get the following error:

#> python coord.pyc

File “coord.pyc”, line 1
m?
^
SyntaxError: invalid syntax

Any idea on what I’ve done wrong ?

thx.

It’s okay to byte-compile all but the main script file for the gateway. You’re trying to run the .pyc file directly. That file should be left a standard .py.

If it’s large and complicated, you could as an option make a very simple script that imports and runs your code and still take advantage of the byte-compiled .pyc.

Don’t you just wish that someone would write the step-by-step guide?
Here’s what it means to compile on a Digi X_
Here are the benefits of compiling
Here are the references to Python (and versions) you should read and refer to.
Here is how you do it
Here are different ways to do it
Here are the options you can use.
Here is what you put in the auto-start entry
etc.

Yes - I know we use standard Python.
But when people start using other devices, sometimes there are nuances to handle.

I love Python on this system, but its not well documented for the transition. Sure - its “easy” for experts and people at Digi.

I still like how it works!