Python loading old version of sklearn
Asked Answered
A

2

14

I've installed version 0.18.2 of scikit-learn on my Mac using

pip uninstall scikit-learn
pip install scikit-learn==0.18.2

However, when I run

python
>>> import sklearn
>>> sklearn.__version__

I get

'0.17'

Interestingly, this older version is still installed even after I uninstall scikit-learn. Could this have something to do with multiple versions of Python somehow being installed? I beat my head against the wall trying to use Anaconda at one point to try to get numpy and scipy running, and have since switched to ActivePython. When I run

which python

I get

/Library/Frameworks/Python.framework/Versions/2.7/bin/python

I know there are very similar questions on SO, but none of the posted solutions have worked.

Aport answered 10/8, 2017 at 16:17 Comment(0)
K
4

Check your python path. On unix:

echo $PYTHONPATH

This will output all paths used for module imports. You might have some old version installed elsewhere.

Kerbstone answered 10/8, 2017 at 16:20 Comment(2)
Bingo! I set PYTHONPATH=/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages to match the result from pip --version suggested by @JoshuaRLi. Thanks!Aport
@yearling had myself messed up more than once with this ;) Now I leave this empty and use conda, no more issues!Kerbstone
M
6

You have to make sure that the pip you are invoking is the pip executable that belongs to the python that you are invoking. Otherwise, you're installing python packages to the wrong version, if you have multiple versions on your machine.

pip --version will list the Python version associated with whatever pip you invoked.

python -m pip install scikit-learn --upgrade will use whatever python you're invoking to invoke its own installation of pip (if it exists). This should work in your use case because it lets you not worry about whatever your pip maps to.

Milky answered 10/8, 2017 at 16:21 Comment(4)
Any 5-second hints before I spend 5 minutes figuring out how to do this? In particular pip2.7 --install scikit-learn==0.18.2 is giving me the same behavior.Aport
@yearling Don't worry, I tend to update my answers quickly with additional information :)Milky
pip --version yields: pip 9.0.1 from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (python 2.7). python -m pip install scikit-learn --upgrade yields Requirement already up-to-date: scikit-learn in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packagesAport
pip --version was critical to solution, see comment to @Y0da. Thanks!Aport
K
4

Check your python path. On unix:

echo $PYTHONPATH

This will output all paths used for module imports. You might have some old version installed elsewhere.

Kerbstone answered 10/8, 2017 at 16:20 Comment(2)
Bingo! I set PYTHONPATH=/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages to match the result from pip --version suggested by @JoshuaRLi. Thanks!Aport
@yearling had myself messed up more than once with this ;) Now I leave this empty and use conda, no more issues!Kerbstone

© 2022 - 2024 — McMap. All rights reserved.