Python samples are now bundled in a package

  • September 16, 2016
  • Magnus Carlsson

This blog uses now deprecated functions, see blog “Improved API in Python canlib v1.5” for more information.

With the release of CANlib SDK v5.17, the packaging of the Python samples has been revamped. Instead of just releasing the bare Python files, the files are now placed in a Python Wheel as well as a .zip package for easy installation.

Hopefully, despite that you now will need to change your current Python scripts, the benefits of the new way of packaging will outweigh the hassle.

We support Python 2.7 but do not yet have full support for Python 3.4+ (there are some known issues with Unicode strings).

Bug reports, contributions, suggestions for improvements, and similar things are much appreciated and can be sent by e-mail to [email protected].


We first need to install the DLLs or shared object files that the Python CANlib wrapper depends upon.


On Windows, install the `canlib32.dll’ by downloading and installing “Kvaser Drivers for Windows” which can be found on the Kvaser Download page. This will also install all the .dll files used by `kvrlib’.

The Kvaser CANlib SDK also needs to be downloaded from the same place and installed if the kvmlib wrapper is to be used.


On Linux, install the by downloading and installing “Kvaser LINUX Driver and SDK” which can be found on the Kvaser Download page.

Currently, only Kvaser CANlib is supported on Linux.

Python Package

The next step is to install the Python canlib package which can be found in the Python directory, under Samples, where you installed the CANlib SDK. Install the Python package using e.g. pip (where x.y.z is the version number):

pip install

Update 2018-04-12: In newer canlib releases you instead install the wheel with:

pip install canlib-x.y.z-py2.py3-none-any.whl

If you are running a recent version of Python (Python 3.4, Python 2.7.9 or later) you already have pip. If you are running an earlier version of Python, you may install pip following the installation instructions here.


The python package will try its best to find out where CANlib SDK is installed in order to find the .dll files. If that fails, or you just want to tell the module where the needed .dll are placed, set the environment variable `KVDLLPATH’ to point to the directory in question.

Since the Python code now is placed inside a module we must also add the module name ‘canlib’ to the import and usage statements, e.g. like this:

import canlib.canlib as canlib

cl = canlib.canlib()
print("canlib version: %s" % cl.getVersion())


As we are using pip, we can show details about the installed Python package:

pip show canlib

We may also uninstall the package using:

pip uninstall canlib
Author Image

Magnus Carlsson

Magnus Carlsson is a Software Developer for Kvaser AB and has developed firmware and software for Kvaser products since 2007. He has also written a number of articles for Kvaser’s Developer Blog dealing with the popular Python language.