This tutorial shows how to get started with the LEADTOOLS SDK in a Python Console application.
Overview | |
---|---|
Summary | This tutorial covers how to set a license in a Python console application. |
Completion Time | 15 minutes |
Visual Studio Project | Download tutorial project (1 KB) |
Platform | Python Console Application |
IDE | Visual Studio 2022 |
Runtime License | Download LEADTOOLS |
Try it in another language |
|
Before any functionality from the SDK can be leveraged, a valid runtime license will have to be set.
For instructions on how to obtain a runtime license refer to Obtaining a License.
The LEADTOOLS SDK for Python requires Python.NET to be installed on the device.
First ensure that Python is installed on the device by running the following command in the Command Prompt:
python --version
Install Python.NET by running the following command in the Command Prompt:
pip install pythonnet
There are two ways to incorporate LEADTOOLS in your Python application. The first option is to use the package included with the LEADTOOLS download.
The second method is to use the LEADTOOLS pip package. This can be downloaded by running the following command in the Command Prompt
pip install leadtools
The application will now use the freshly installed pip package rather than the included package.
Launch Visual Studio and click Create a new project.
Select Python Application and click Next.
Add the project name and specify the location to save the project to. Then click Create.
First, update the DemosTools.py file to reference the LEADTOOLS installation path.
DemosTools.py can be found at the following directory: <INSTALL DIR>/LEADTOOLS22/Examples/Common/Python
Update the two file paths in the get_bin()
method to point to the <INSTALL DIR/LEADTOOLS22/Bin>
file path.
Add the below code to the Project-Name.py file to import the necessary dependencies for the project.
import os
import sys
# Import LEADTOOLS Demo common modules
sys.path.append("C:/LEADTOOLS22/Examples/Common/Python")
from DemosTools import *
from UnlockSupport import Support
# Add reference to LEADTOOLS
from leadtools import LibraryLoader
LibraryLoader.add_reference("Leadtools")
from Leadtools import RasterSupport
Now that the LEADTOOLS references have been added to the project, add the relevant code to set your license.
In the Project-Name.py file add a new method called main()
. Add the below code to properly set the LEADTOOLS native runtimes and LEADTOOLS license.
def main():
Support.set_license("C:/LEADTOOLS22/Support/Common/License")
if (RasterSupport.KernelExpired):
print("License file invalid or expired.");
else:
print("License file set successfully.");
main()
Run the project by pressing F5, or by selecting Debug -> Start Debugging.
If the steps were followed correctly, a message will appear in the console showing License file set successfully
.
This tutorial covered the steps to implement a new Python project that references the LEADTOOLS SDK .NET 6 assemblies. It showed the steps to set the LEADTOOLS SDK license and the project execution flow.
All functionality in the LEADTOOLS SDK is unlocked via setting a license with the SetLicense
method before calling any LEADTOOLS SDK functions.
Once the SDK is purchased, the evaluation license can be replaced with a valid runtime license to disable the Nag Message.
This tutorial is the basis for all Python console applications leveraging the LEADTOOLS SDK.