Skip to main content
Skip table of contents

Python for LJM - Windows, Mac, Linux

Cross-platform Python wrapper and examples for the LJM library.

Prerequisites

You may also wish to go to your device Quickstart Tutorial and confirm basic operation.

Latest labjack-ljm Release Package

Python_LJM_2020_11_20.zip

  • Up to date with LJM version 1.21.

  • Added device reconnect callback functionality and example.

  • Added stream-out function support and examples.

  • Added a Lua control example.

GitHub

This package is available on GitHub: github.com/labjack/labjack-ljm-python

Getting Started

  1. Install the LJM Library. Note that this is different from the labjack-ljm package.

  2. Install labjack-ljm. See the "Installing labjack-ljm" section below.

  3. See our basic examples for an overview of how to use LJM to access device registers:
    https://github.com/labjack/labjack-ljm-python/tree/master/Examples/Basic

  4. Go through the T-series Datasheet and LJM User's Guide for more in-depth information about device control.

Installing labjack-ljm

To run LJM using Python, both the LJM library and the labjack-ljm Python package must be installed. There are three common options to install labjack-ljm.

Option 1: Pip Install

labjack-ljm is typically installed using pip. To use pip, open a terminal or console window and use the following command:

python -m pip install labjack-ljm

or:

pip install labjack-ljm

Run the command with sudo on Linux and Mac.

Option 2: Conda Install (Not Recommended)

This install option should only be considered if you are already using Conda. We currently do not distribute Conda packages. If you are using Conda, we suggest creating a skeleton package from our PyPi package, then install with Conda:

conda skeleton pypi labjack-ljm

conda-build labjack-ljm

conda install --use-local labjack-ljm

There is also an alternative recipe builder called Grayskull made by the Conda community that could be used instead of skeleton (and it is supposed to be better than the skeleton tool):

grayskull pypi --strict-conda-forge labjack-ljm

Option 3: Setup Script Install (Not Recommended)

labjack-ljm can be installed via the .zip file at the top of this page using the included setup.py script. This is a legacy installation option and we would recommend using pip to install the package in most situations.

To install the package using the setup.py, download/extract the .zip file attached at the top of this page. In a terminal or console, navigate to the extracted folder and run the following command:

python setup.py install

Run the command with sudo on Linux and Mac.

Examples

labjack-ljm examples are in the .zip file attached at the top of this page.

Refer to the download's README.TXT file for requirements, installation, installation troubleshooting, documentation, and license information.

Troubleshooting

Make sure labjack-ljm is installed for the current version of Python

Many computers have multiple installations of Python. The following error indicates that labjack-ljm is not installed for the current version of Python:

ImportError: No module named labjack

Make sure you install labjack-ljm for the Python version you are using. For example, on Linux if both Python 2.7 and 3.5 are installed, you can install labjack-ljm to Python 3.5 with:

      $ python3.5 -m pip labjack-ljm install

Check the Python path

To check what the path of the Python executable is:

  • Windows - Open cmd and use: where python

  • macOS or Linux - Use: which python

You can also check where python3 is, or any other version of Python. For example: where python3 or which python3

Windows - Make sure Python is installed and added to the path

Running python setup.py install may cause the following error:

'python' is not recognized as an internal or external command, operable program or batch file.

In this case, either Python is not installed on your computer or the Python executable was added to the path.

To resolve this, run the Python Windows installer. As shown below, click "Add python.exe to Path" (you may have to scroll down) and select "Will be installed on local hard drive".



Then continue the installation as normal: Go through the above instructions to install labjack-ljm again. To refresh the path, you may need to first open a new terminal or console.

Running Python without adding it to the path

After Python is installed you can run the Python executable from its path without adding it to the path. For example:

C:\Python27\python.exe -m pip labjack-ljm

The above command uses the Python 2.7 path. Make sure you use the correct path for your installation of Python.

Adding Python to the Windows path

Usually Python is added to the user path, as shown above. Another option is to manually add the Python executable path to the Windows path as described in the Python documentation.

LJM Overview

With the LJM library, pretty much everything you might want to do with a device is accomplished by writing and/or reading some registers.  Look at the T-series Datasheet or the Modbus Map to determine what registers you need to write and read, then use eWriteName (or eWriteNames) to write the desired registers and eReadName (or eReadNames) to read the desired registers.  The following examples in the Basic folder are a great place to start:

  • LJM_eWriteName Example

  • LJM_eWriteNames Example

  • LJM_eReadName Example

  • LJM_eReadNames Example

  • Write Read Loop with Config

Where is an example to do XYZ?

You will find lots of examples in this archive, but there is not an example for everything the LabJack can do.  The reason for this stems from the "Overview" section above.  Most operations simply involve writing and reading different registers, so you really just need examples that show you how to write and read any register.  If we had examples for every operation, they would just be copies of the example "Write Read Loop with Config" with different registers. The typical workflow to do almost anything beside stream is:

  1. Look at the T-series Datasheet or the Modbus Map to determine what registers you need to write and read.

  2. Use the Register Matrix in Kipling to test writing and reading your desired registers and confirm you see what you expect to see.  This step is optional and not always applicable.

  3. Use eWriteName (or eWriteNames) to write the desired registers and eReadName (or eReadNames) to read the desired registers. Or just use "Write Read Loop with Config", which provides the basic structure used by many user applications.

Code Snippet

CODE
from labjack import ljm

# Open first found LabJack
handle = ljm.openS("ANY","ANY","ANY")
# Call eReadName to read the serial number from the LabJack.
name ="SERIAL_NUMBER"
result = ljm.eReadName(handle, name)
print("\neReadName result: ")
print("    %s = %f"%(name, result))

Old Versions

Download Python_LJM_2020_11_20.zip

  • 11/20/2020

  • Release

  • Up to date with LJM version 1.21.

  • Added device reconnect callback functionality and example.

  • Added stream-out function support and examples.

  • Added a lua control example.

Download Python_LJM_2019_04_03.zip

  • 04/03/2019

  • Release

  • Up to date with LJM version 1.20.

  • Added string support to eWriteAddressByteArray and eWriteNameByteArray.

  • Changed distribution name from LJMPython to labjack-ljm

  • Added SD examples.

Download Python_LJM_2018_10_19.zip

  • 10/19/2018

  • Release

  • Up to date with LJM version 1.19.

  • Added stream callback functionality.

  • Added and updated some examples.

Download Python_LJM_2018_02_23.zip

  • 02/23/2018

  • Release

  • Up to date with LJM version 1.18.

  • Added and updated some examples.

Download Python_LJM_2017_12_04.zip

  • 12/04/2017

  • Release

  • Up to date with LJM version 1.16.

  • Added new examples.

  • Added T4 support to examples.

Download Python_LJM_2015_12_03.zip

  • 12/03/2015

  • Release

  • LJM Python version 1.1.0

  • Up to date with LJM version 1.0900

Download Python_LJM_2015_08_28.zip

  • 08/28/2015

  • Release

  • LJM Python version 1.0.0

  • Up to date with LJM version 1.0806

Download Python_LJM_2015_06_30.zip

  • 06/30/2015

  • Release

  • LJM Python version 1.0.0

  • Up to date with LJM version 1.0806

Download Python_LJM_2015_06_25.zip

  • 06/25/2015

  • Release

  • LJM Python version 1.0.0

  • Up to date with LJM version 1.0806

Download Python_LJM_2015_05_21_0.zip

  • 05/21/2015

  • Release

  • LJM Python version 0.9.3

  • Up to date with LJM version 1.0800

Download Python_LJM_2014_10_09.zip

  • 10/09/2014

  • Release

  • LJM Python version 0.9.2

  • Up to date with LJM version 1.0702

  • Updated 10/09/2014

File List

Python_LJM_2020_11_20.zip contains:

CHANGES.TXT
LICENSE.TXT
README.TXT
setup.cfg
setup.py
Examples\Basic\eAddresses.py
Examples\Basic\eNames.py
Examples\Basic\eReadAddress.py
Examples\Basic\eReadAddresses.py
Examples\Basic\eReadName.py
Examples\Basic\eReadNames.py
Examples\Basic\eWriteAddress.py
Examples\Basic\eWriteAddresses.py
Examples\Basic\eWriteName.py
Examples\Basic\eWriteNames.py
Examples\Basic\write_read_loop_with_config.py
Examples\More\1-Wire\1_wire.py
Examples\More\AIN\dual_ain_loop.py
Examples\More\AIN\single_ain.py
Examples\More\AIN\single_ain_with_config.py
Examples\More\Config\read_config.py
Examples\More\Config\read_device_name_string.py
Examples\More\Config\write_device_name_string.py
Examples\More\Config\write_power_config.py
Examples\More\DIO\single_dio_read.py
Examples\More\DIO\single_dio_write.py
Examples\More\DIO_EF\dio_ef_config_1_pwm_and_1_counter.py
Examples\More\Ethernet\read_ethernet_config.py
Examples\More\Ethernet\read_ethernet_mac.py
Examples\More\Ethernet\write_ethernet_config.py
Examples\More\I2C\i2c_eeprom.py
Examples\More\List_All\list_all.py
Examples\More\Lua\lua_execution_control.py
Examples\More\SD\__init__.py
Examples\More\SD\change_directory.py
Examples\More\SD\delete_file.py
Examples\More\SD\get_disk_info.py
Examples\More\SD\list_directory.py
Examples\More\SD\print_working_directory.py
Examples\More\SD\read_file.py
Examples\More\SD\sd_util.py
Examples\More\SPI\spi.py
Examples\More\Stream\advanced_aperiodic_stream_out.py
Examples\More\Stream\ljm_stream_util.py
Examples\More\Stream\periodic_stream_out.py
Examples\More\Stream\stream_basic.py
Examples\More\Stream\stream_basic_with_stream_out.py
Examples\More\Stream\stream_burst.py
Examples\More\Stream\stream_callback.py
Examples\More\Stream\stream_in_with_aperiodic_stream_out.py
Examples\More\Stream\stream_sequential_ain.py
Examples\More\Stream\stream_triggered.py
Examples\More\Testing\auto_reconnect_test.py
Examples\More\Testing\c-r_speed_test.py
Examples\More\Watchdog\read_watchdog_config.py
Examples\More\Watchdog\write_watchdog_config.py
Examples\More\WiFi\read_wifi_config.py
Examples\More\WiFi\read_wifi_mac.py
Examples\More\WiFi\read_wifi_rssi.py
Examples\More\WiFi\write_wifi_config.py
labjack\__init__.py
labjack\ljm\__init__.py
labjack\ljm\constants.py
labjack\ljm\errorcodes.py
labjack\ljm\ljm.py

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.