The actions described on the scikit-learn website work irrespective of the scikit-learn version in EPD. Python will automatically use the scikit-learn version set in the PYTHONPATH
environment variable, which you should set to the directory path of the Git version of scikit-learn.
If you use Bash on a Unix-like system, you should do the following:
- Perform the actions to install scikit-learn's latest code (in this example I cloned it to
/home/yourname/bin/scikit-learn
)
- Edit
.bashrc
and add the line: export PYTHONPATH="/home/yourname/bin/scikit-learn";
- Open a new terminal and start Python in interactive mode by typing
python
- Type:
import sklearn
- Type:
sklearn.__verion__
this should now show '0.12-git'
instead of 0.11
Why does this work? Python uses the variable sys.path
(a list
of paths) internally to keeps track of all the directories where it should look for modules and packages. Once a module or package is requested, Python will sequentially go through this list until it has found a match. So, e.g., a module can be listed multiple times in sys.path
, but only the version which appeared first in the list will be used.
Every Python installation will have its own default set of paths listed in sys.path
. One way of extending sys.path
is by listing paths in PYTHONPATH
. Once Python starts it will read this environment variable and add it to the start of the sys.path
list. So if you add the path to another version of scikit-learn to your PYTHONPATH
then (EPD's) Python will find that version of scikit-learn first and use it instead of the version listed further on in sys.path
.
To view sys.path
, simply import sys
and then print sys.path
. Also, e.g., if you only want to use the 0.12 version of scikit-learn in one Python program and use the 0.11 version as default in all other Python programs then you could leave the PYTHONPATH
empty and only insert the path to scikit-learn 0.12 manually at the top of your code:
import sys
sys.path.insert(0, '/home/yourname/bin/scikit-learn')
import sklearn