Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

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.

like image 319
onigiri Avatar asked Jan 30 '16 15:01

onigiri


People also ask

How do I fix No module named pip?

To fix the error with python -m pip To verify that, run python --version . If you get a Python 2 version, try python3 --version . If you don't get errors (and receive a Python 3 version), replace python -m pip with python3 -m pip . That should fix your No module named pip issue.

Why pip is not working in Python?

One of the most common problems with running Python tools like pip is the “not on PATH” error. This means that Python cannot find the tool you're trying to run in your current directory. In most cases, you'll need to navigate to the directory in which the tool is installed before you can run the command to launch it.


3 Answers

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.

like image 185
Loïc Avatar answered Oct 21 '22 19:10

Loïc


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
like image 29
vishnu viswanath Avatar answered Oct 21 '22 20:10

vishnu viswanath


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
like image 2
Julio Cezar Silva Avatar answered Oct 21 '22 20:10

Julio Cezar Silva