Python for LJM - Windows, Mac, Linux | LabJack
 
« Close

Datasheets and User Guides

App Notes

Software & Driver

 

Python for LJM - Windows, Mac, Linux

Subsections

LJM Python Wrapper/Examples Windows/Mac/Linux (Software Platform)

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

Release

LJM Python Wrapper/Examples Top (Referencable)

GitHub:

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

Prerequisites

You may also wish to go to the T4 or T7 Quickstart Tutorial and confirm basic operation.

Installing labjack-ljm

To run LJM using Python, both the LJM library and the labjack-ljm Python package must be installed.

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.

Alternately, labjack-ljm can be installed via the .zip file. To do so, 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 Examples Where Is An Example To Do XYZ (Referencable)

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 device's datasheet (T7 or T4) 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.

Stream mode and other operations that don't fit in "Write Read Loop with Config" will usually have specific examples, and if something seems to be missing let us know.

LJM Python Wrapper/Examples Bottom (Referencable)

Code Snippet

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))

File list

Python_LJM_2019_04_03.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\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\in_stream_with_non_looping_out_stream.py
Examples\More\Stream\ljm_stream_util.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_sequential_ain.py
Examples\More\Stream\stream_triggered.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

5 comments

Is this package available for a pip install, I have the enthout canopy python distribution and it seems the only way to install external packages is via pip.

LabJack Support's picture

It looks like you can install the package on this page using pip since it contains a setup.py file for installation.

Try downloading the zip file and running (replace path/to to the directory the file is):

pip install path/to/Python_LJM_2013_12_30.zip

Alternatively, over the network you can try:

pip install http://labjack.com/sites/default/files/2013/12/Python_LJM_2013_12_30.zip

Note that the download's URL and zip file name uses dates, so future releases will have different URL paths and names. Before running either of the above commands, use the current "File attachment" download's URL or zip file name in your "pip install" command.

Can I get a simple Python example to start with LabJack T7 Pro ?

Are there Python code examples for the U3?

You'll want to take a look at the LabJackPython download (it has examples) and the quickstarts:

http://labjack.com/support/labjackpython

The LJM driver/wrapper currently only supports the LabJack T7 and Digit. Older LabJacks such as the U12, UE9, U3 and U6 are supported in LabJackPython.