Solution: liblinear “Module not Found” | Python

Winnie Yap Xiang Loo
4 min readSep 7, 2022

--

Have you ever get stuck while installing packages in Python environment so that you use the library to perform some task or train your model?

No module named ‘liblinearutil’ after pip install liblinear

Here I am today. Get stuck for 5 hours dealing with the package “liblinear”. I have visited the official package resources website https://www.csie.ntu.edu.tw/~cjlin/liblinear/ to seek for solution to install the package successfully and Google out a bunch of question/error I got from installing the package.

My goal is to install the liblinear package, later import in Jupyter lab to use functions within the package. The problem does not exist in the installation process (pip install liblinear working fine and showed successfully installed) but importing caused “Module Not Found” problem.

All of the Googled solution turns out not working for me (Stack Overflow too). :(

The Solution Finding Journey

Here’s what I’ve done. As I am installing liblinear library to use their functions in training linear model, I seek for training code samples (source code) where people write code to use liblinear library to train their model. After going through numbers of source of code, I realized there is an alternative approach:

“Install the package file (manually or git clone), then import manually into Jupyter cell through Python code.”

It might seems hard or tough work at first, but after understanding and running through the codes, it is actually quite easy and it most importantly, IT SOLVED MY PROBLEM, THINGS ARE WORKING NOW! ❤

Below are the compilations of code that I have run, hope it helps people that need it, and for myself for future reference too (cause I never remember these codes with my little small brain, I just Googled whenever I need.. )

Part 1: Manually Download Files of Package from GitHub

Here’s a snippet of directory in Github, where liblinear-1.96 is the file i needed to installed and import manually into Jupyter.

liblinear-1.96 needed to install and import manually to successfully use liblinear functions.

To install the liblinear-1.96 file into my Jupyter lab, I have use terminal with command below to clone the file required, later move to directory I am using. Note that github-repo-http is varied based on the repo you would like to clone. Read the following example(demo) for more info.

git clone github-repo-http

All you need to do is go to the GitHub repository that you want to download certain files, copy to get the hyperlink.

Later get back to your terminal as paste with the command git clone, once the cloning is successful, you will see the files you need are on your local Jupyter lab.

Part 2: Setting Up to Import Package/Library in Jupyter cell

Let’s take a look on what I found from other’s source code:

This is what the source code written I found.

If you’re a beginner, you might get drunk with the os.path.join, os.path.dirname, sys.path.append or os.path.abspath.

os.path.join, os.path.dirname, sys.path.append or os.path.abspath

os.path.join — it acts as a path concatenation functions, join 1 or more path component such as “home/user” joined with “training/liblinear-1.96”.

os.path.join Example

os.path.dirname — it helps to get directory name from specified path

os.path.dirname Example

os.path.abspath — return a normalized absolute version of path name. Such as liblinear-1.96 is being entered, it will return the full path (refer to image below).

os.path.abspath Example

sys.path.append — add specific path for interpreter to search. By running sys.path.append with specified path directory for a package, it will help to import the functions within package successfully.

I have did some amendment on the source code found, and below snippet are my final codes that use to import liblinear for training model.

Final Successful Code to Import liblinear

Solved!

Thanks for reading. Happy Coding!!

--

--