Create Python Application Using Library Compiler App
This example shows how to compile a MATLAB® function into a Python® package using the Library Compiler app. Alternatively, if you want to create a Python package from the MATLAB command window using a programmatic approach, see Package MATLAB Function and Deploy to Python Application.
1. On the MATLAB Apps tab, on the far right of the Apps section, click the arrow. In Application Deployment, click Library Compiler. Alternatively, you can open the Library Compiler app from the MATLAB command prompt using the
2. In the Type section of the toolstrip, click Python Package. In the Library Compiler app project window, specify the files of the MATLAB application that you want to deploy.
a. In the Exported Functions section of the toolstrip, click .
b. In the Add Files window, browse to the example folder, and select the function you want to package. Click Open.
The function is added to the list of exported function files. Repeat this step to package multiple files in the same application.
For this example, select the
makesqr.m file that you wrote earlier.
3. In the Packaging Options section of the toolstrip, decide whether to include the MATLAB Runtime installer in the generated application by selecting one of the options:
Runtime downloaded from web — Generate an installer that downloads the MATLAB Runtime and installs it along with the deployed MATLAB application. You can specify the file name of the installer.
Runtime included in package — Generate an application that includes the MATLAB Runtime installer. You can specify the file name of the installer.
Note The first time you select this option, you are prompted to download the MATLAB Runtime installer.
Specify Package Settings
Next, define the name of your Python package.
Choose a name for your package. The Library Name field is automatically populated with
makesqras the name of the package. Rename it as
MagicSquarePkg. For more information on naming requirements for the Python package, see Install Python Package.
Create Sample Driver File
You can add MATLAB files to the project to generate sample Python driver files. Although Python driver files are not necessary to create a package, you can use them to implement a Python application, as shown in Package MATLAB Function and Deploy to Python Application.
In the Samples section, select Create New Sample, and click
makesqr.m. A MATLAB file opens for you to edit.
% Sample script to demonstrate execution of function y = makesqr(x) x = 0; % Initialize x here y = makesqr(x);
x = 0 to
x = 5, save the file, and return to the Library Compiler app.
You must edit the MATLAB sample file to output your desired result. Generated target language sample files use the same inputs and outputs as the sample MATLAB file.
The compiler converts this MATLAB code to Python code during packaging. For more information and limitations, see Sample Driver File Creation.
Customize the Application and Its Appearance
Customize the Application and Its Appearance
In the Library Compiler app, you can customize the installer, customize your application, and add more information about the application.
Library information — Information about the deployed application. You can also customize the appearance of the application by changing the application icon and splash screen. The generated installer uses this information to populate the installed application metadata. See Customize the Installer.
Additional installer options — Default installation path for the generated installer and custom logo selection. See Change the Installation Path.
Files required for your library to run — Additional files required by the generated application to run. These files are included in the generated application installer. See Manage Required Files in Compiler Project.
Files installed for your end user — Files that are installed with your application. See Specify Files to Install with Application.
Package the Application
When you are finished selecting your packaging options, save your Library Compiler project and generate the packaged application.
1. Click Package.In the Save Project dialog box, specify the location to save the project.
2. In the Package dialog box, verify that Open output folder when process completes is selected. When the packaging process is complete, examine the generated output in the target folder.
Three folders are generated:
for_testing. For more information about the files generated in these folders, see Files Generated After Packaging MATLAB Functions.
The log file
PackagingLog.htmlcontains packaging results.