7

I'm a new to Python, and I have a trouble in import library.

I wrote a code

from sklearn.linear_model import LogisticRegression

then I got an error

ImportError                               Traceback (most recent call last)
<ipython-input-19-c84b03903d9e> in <module>()
----> 1 from sklearn.linear_model import LogisticRegression

/usr/lib/python2.7/dist-packages/sklearn/linear_model/__init__.py in <module>()
     10 # complete documentation.
     11 
---> 12 from .base import LinearRegression
     13 
     14 from .bayes import BayesianRidge, ARDRegression

/usr/lib/python2.7/dist-packages/sklearn/linear_model/base.py in <module>()
     22 
     23 from ..externals import six
---> 24 from ..externals.joblib import Parallel, delayed
     25 from ..base import BaseEstimator, ClassifierMixin, RegressorMixin
     26 from ..utils import as_float_array, atleast2d_or_csr, safe_asarray

/usr/lib/python2.7/dist-packages/sklearn/externals/joblib/__init__.py in <module>()
      1 # yoh: use system-wide joblib
      2 
----> 3 from joblib import *

ImportError: No module named joblib

in IPython. I'm using ubuntu and I installed scikit_learn-0.18 by using "sudo apt-get install python-sklearn" command but encountered above error. I also tried to use "sudo easy_install joblib" but the error was not erased.

What is wrong? Would you help me? Thank you.

2
  • have you tried installing that module separately, for example with pip install joblib? Commented Jan 30, 2016 at 15:13
  • No I have not. I need to try it. Commented Jan 31, 2016 at 6:00

5 Answers 5

10

pip is python's packet manager. It's shipped by default with python since version 3.4, so you should probably use it.

Usually for now, python on linux redirects to python2.7 and there is kind of a problem with upgrading to python3.x because of some old linux tools.

So you'll probably have both python2.7 and python3.x on your OS at some point.

If you aren't sure if you have pip for the version of python you want to use install it :

cd /tmp
wget https://bootstrap.pypa.io/get-pip.py
python3.4 get-pip.py # install pip for any python -v (3.4 here but replace with yours)
rm get-pip.py -f

Now pip is installed, and you can use it to search / install / upgrade / remove / ... python packets.

So let's install joblib :

python3.4 -m pip install joblib # install packets for a particular version easily

As you can see I don't use pip install but python3.x -m pip install so pip installs the libraries for that specific version of python.

Sign up to request clarification or add additional context in comments.

1 Comment

py -3 -m pip install joblib should also do the job. If you know the certain version of python then: py -3.4 -m pip install joblib (for python 3.4).
6

For me I had the wrong version of joblib installed. Reintalling sklearn and joblib solved the issue.

pip uninstall sklearn
pip uninstall joblib

pip install sklearn
pip install joblib

Comments

2

I'm on pip 20.0.2 and python 3.7, and other solutions in here didn't work for me - probably because it all happend on a new conda env.

My env was cloned from the root (conda create -n myenv --clone base) so it might've had influence in joblib not being there, and pip install joblib having no effect. Maybe there's a specific indexing issue in conda env cloning, but I did manage to solve this by

conda install joblib

Comments

1

Mentioning the specific version didn't work for me, still cause the same error I'm using a virtualenv on vs code This solved it for me

pip install joblib 

(installed 1.1 which it didn't previously)

Comments

0

The Python way to install dependencies is pip, but I prefer to use OS official dependencies when available to avoid loosing compatibilty and updates related to OS package manager. In Ubuntu there are a lot of python packages which have two different versions: one for Python 2.7 and one for Python 3.4. First of all try to install joblib searching for python3-joblib package name for python 3 or python-joblib for python 2. If your version of Ubuntu still not have the required dependency you can use pip (pip2.7 or pip3.4, both available as python-pip and python3-pip packages).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.