Python: No module named ... How to use pip

36,871

Solution 1

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.

Solution 2

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

Solution 3

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

Solution 4

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)

Share:
36,871
Admin
Author by

Admin

Updated on July 25, 2022

Comments

  • Admin
    Admin almost 2 years

    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.