Add References and Set a License - Python

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

Required Knowledge

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.

Install Python.NET

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

Getting Started with LEADTOOLS in a Python Application

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.

Create the Project

Launch Visual Studio and click Create a new project.

Creating new Visual Studio project

Select Python Application and click Next.

Creating new Console App Python

Add the project name and specify the location to save the project to. Then click Create.

Adding Visual Studio project name and location

Add Search Paths and Set LEADTOOLS References

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.

the updated DemosTools.py get_bin method

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 

Add the Set License Code

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

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.

Viewing console message that indicates license is set successfully

Wrap-up

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.

See Also

Help Version 22.0.2024.3.20
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.


Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.