UCSD ECE276A: Sensing & Estimation in Robotics (Fall 2017)
Instructions for creating cross platform executable files from Python code.
Windows
This document describes how to create an executable file on Windows using the software ‘cx_Freeze’.
Download and install the appropriate version of cx_Freeze as per your OS (32/64 bit) as mentioned in the webpage. Note: You may need to get pip first by using this link.
Create and build your Python program. Create a new python file (.py) called ‘setup.py‘in the same directory as your program file. Type the following in the setup file.
from cx_Freeze import setup, Executable
setup(
name = "<any name>",
version = "<any number>",
description = '<any description>',
executables = [Executable("<program.py>")]
)
Open the command prompt from run in the Start Menu and go to the respective Python Directory. Type ‘python setup.py build’ and press enter. It should take few seconds to build your executable file. Once done, a folder called ‘build’ will appear in the Python directory. An executable file with the name of your program should be present there. Run and test it.
Mac
This documentation shows how to generate a distributable app for Python on Mac OS. It is tested on Sierra 10.12.6. py2app is used based on this tutorial.
Install Python 3 and OpenCV 3 following this blog post. Installation of Python 2 and OpenCV 2 can be found in the same blog.
Install ‘py2app‘ by ‘pip install -I py2app==0.12‘.
Do not use the latest 0.14 version, due to a bug reported here.
Suppose the python code is named ‘test.py‘, then run ‘py2applet –make-setup test.py’ to generate a setup file.
Next, run ‘rm -rf build dist’ to delete the old build folders.
Finally, run ‘./dist/test.app/Contents/MacOS/test “~/models/easy.pickle” “~/trainset” –plot’, where one would normally run ‘test.py’ as ‘python test.py “models/easy.pickle” “trainset” –plot’.
Note that the path for the app should be an absolute path, instead of relative path.
Linux
cx_Freeze should work for Linux as well. If you are using Linux, you don't have to make an executable but make sure to document well how to run your code and what version of python/opencv you are using in the README file.
|