There are different ways to install scikit-learn:
Downloads Mac OS X; Python Releases for Mac OS X. Latest Python 3 Release - Python 3.4.0; Latest Python 2 Release - Stable Releases. Download Mac OS X installer; Python 2.3.7 - March 11, 2008. No files for this release. Python 2.4.5 - March 11, 2008. No files for this release. Oct 09, 2020 Prerequisites for installing Python3 on Mac Install Xcode. Xcode is Apple's Integrated Development Environment (IDE). You might already have Xcode on your Mac.
- Install the latest official release. Thisis the best approach for most users. It will provide a stable versionand pre-built packages are available for most platforms.
- Install the version of scikit-learn provided by youroperating system or Python distribution.This is a quick option for those who have operating systems or Pythondistributions that distribute scikit-learn.It might not provide the latest release version.
- Building the package from source. This is best for users who want thelatest-and-greatest features and aren’t afraid of runningbrand-new code. This is also needed for users who wish to contribute to theproject.
Installing the latest release¶
Operating SystemPackager
Install the 64bit version of Python 3, for instance from https://www.python.org.Install Python 3 using homebrew (
brew install python
) or by manually installing the package from https://www.python.org.Install python3 and python3-pip using the package manager of the Linux Distribution.Install conda (no administrator permission required).Then run:
In order to check your installation you can use
Note that in order to avoid potential conflicts with other packages it isstrongly recommended to use a virtual environment, e.g. python3
virtualenv
(see python3 virtualenv documentation) or conda environments.Using an isolated environment makes possible to install a specific version ofscikit-learn and its dependencies independently of any previously installedPython packages.In particular under Linux is it discouraged to install pip packages alongsidethe packages managed by the package manager of the distribution(apt, dnf, pacman…).
Note that you should always remember to activate the environment of your choiceprior to running any Python command whenever you start a new terminal session.
If you have not installed NumPy or SciPy yet, you can also install these usingconda or pip. When using pip, please ensure that binary wheels are used,and NumPy and SciPy are not recompiled from source, which can happen when usingparticular configurations of operating system and hardware (such as Linux ona Raspberry Pi).
If you must install scikit-learn and its dependencies with pip, you can installit as
scikit-learn[alldeps]
.Scikit-learn plotting capabilities (i.e., functions start with “plot_”and classes end with “Display”) require Matplotlib (>= 2.1.1). For running theexamples Matplotlib >= 2.1.1 is required. A few examples requirescikit-image >= 0.13, a few examples require pandas >= 0.18.0, some examplesrequire seaborn >= 0.9.0.
Warning
Scikit-learn 0.20 was the last version to support Python 2.7 and Python 3.4.Scikit-learn 0.21 supported Python 3.5-3.7.Scikit-learn 0.22 supported Python 3.5-3.8.Scikit-learn now requires Python 3.6 or newer.
Note
For installing on PyPy, PyPy3-v5.10+, Numpy 1.14.0+, and scipy 1.1.0+are required.
Third party distributions of scikit-learn¶
Some third-party distributions provide versions ofscikit-learn integrated with their package-management systems.
These can make installation and upgrading much easier for users sincethe integration includes the ability to automatically installdependencies (numpy, scipy) that scikit-learn requires.
The following is an incomplete list of OS and python distributionsthat provide their own version of scikit-learn.
Arch Linux¶
Arch Linux’s package is provided through the official repositories as
python-scikit-learn
for Python.It can be installed by typing the following command:Debian/Ubuntu¶
The Debian/Ubuntu package is splitted in three different packages called
python3-sklearn
(python modules), python3-sklearn-lib
(low-levelimplementations and bindings), python3-sklearn-doc
(documentation).Only the Python 3 version is available in the Debian Buster (the more recentDebian distribution).Packages can be installed using apt-get
:Fedora¶
The Fedora package is called
python3-scikit-learn
for the python 3 version,the only one available in Fedora30.It can be installed using dnf
:NetBSD¶
scikit-learn is available via pkgsrc-wip:
MacPorts for Mac OSX¶
The MacPorts package is named
py<XY>-scikits-learn
,where XY
denotes the Python version.It can be installed by typing the followingcommand:Canopy and Anaconda for all supported platforms¶
Canopy and Anaconda both ship a recentversion of scikit-learn, in addition to a large set of scientific pythonlibrary for Windows, Mac OSX and Linux.
Anaconda offers scikit-learn as part of its free distribution.
Intel conda channel¶
Intel maintains a dedicated conda channel that ships scikit-learn:
This version of scikit-learn comes with alternative solvers for some commonestimators. Those solvers come from the DAAL C++ library and are optimized formulti-core Intel CPUs.
_ipyw_jlab_nb_ext_conf
Note that those solvers are not enabled by default, please refer to thedaal4py documentationfor more details.
Compatibility with the standard scikit-learn solvers is checked by running thefull scikit-learn test suite via automated continuous integration as reportedon https://github.com/IntelPython/daal4py.
WinPython for Windows¶
The WinPython project distributesscikit-learn as an additional plugin.
Troubleshooting¶
Error caused by file path length limit on Windows¶
It can happen that pip fails to install packages when reaching the default pathsize limit of Windows if Python is installed in a nested location such as the
AppData
folder structure under the user home directory, for instance:In this case it is possible to lift that limit in the Windows registry byusing the
regedit
tool:- Type “regedit” in the Windows start menu to launch
regedit
. - Go to the
ComputerHKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlFileSystem
key. - Edit the value of the
LongPathsEnabled
property of that key and setit to 1. - Reinstall scikit-learn (ignoring the previous broken installation):
Being a software engineer, you often come across many instances where you would require to have Python installed on your Mac.
However, the issue is most modern macOS versions come with rather with Python 2.7.x installed and not the newer, modern version like Python 3.6.5 or Python 3.7.2 (which is the most up-to-date version right now).
This short guide is written to show you how to properly install Python 3 on a Mac OS Xcomputer.
Before you jump into the guide, do take note that there are multiple ways to install Python 3 on a Mac but with this guide, I’ll show you the two easiest ways to do this, step-by-step.
Personally, the way I did it was using a package manager like HomeBrew (it’s okay if you don’t understand what it is). Again, I’ll show you how to do this method down below.
Wait, how do I check if Python 3 is already installed on my Mac?
Simple. Open up your Terminal and type the following line
python --version
and then hit your Enter key:You should see the python version that is currently installed on your Mac.
How to Install Python 3 on macOS: 2 Ways
1. The Simplest Way.
Perhaps the simplest way to install Python 3 on macOS.
This is for you especially if you’re a newbie (though I still strongly recommend you try the HomeBrew method below) or if you don’t want to deal with copy-pasting code into your Terminal and downloading other software.
Here’s how to install Python 3 on your macOS:
- Jump into Python.org downloads page and simply just download the latest Python version.
- Next, run the Python Installer to install Python 3 onto your Mac.
Note
Agate
The Python installation may require about 100MB of disk space to install. Once you’ve installed Python 3 you can have it alongside Python 2 without having to delete the latter from your Mac.
- Great! Now once Python 3 is installed, you’ll be able to find it within the Applications directory of your Mac. You’ll also find here a simple IDE called “IDLE.app” which gives you a basic Python IDE.
Help! Where do I find the Applications directory?
If you can’t find the Applications directory, simply go to Finder by clicking the Finder icon in the Dock (it’s usually the first icon from the left side of the Dock). From there simply, go to the Go menu and select Applications.
Done. If you got yourself lost through the process, you can comment down below.
Next up, I’ll show you how you can install Python 3 using HomeBrew onto your macOS. This is my preferred way and it is just as simple as the method before but it will make your life a whole lot simpler, in the long run, using Python.
2. Install Python 3 on Mac using HomeBrew.
This method is dead-ass simple and a little fun. ?
First of all, you’ll need to have this thing called HomeBrew installed on your Mac. Homebrew is basically a “package manager”. A package manager is an application that helps you install the stuff you need that Apple (or even your Linux System) hadn’t installed in the first place for you.
Python Release Python 3.7.9 | Python.org
It’s simple, fast and safe.
Second, you will need to have installed XCode onto your Mac. If you’re thinking of learning how to program or creating iOS apps on your Mac, then it’s good to have XCode installed. We will be using XCode to install HomeBrew application.
Note
If you have already installed XCode onto your Mac you can skip step 1 and jump straight to step 3.
Here are the steps to install XCode, HomeBrew as well as install Python 3 using HomeBrew onto your Mac:
- Jump into your Terminal app on your Mac and run the copy/paste the following command into the Terminal to install XCode onto your Mac:
- Simply click through all the confirmation crap that XCode shows. It may take a little while to install XCode since it is a large program.
- Great! Now that you have XCode installed, you can install HomeBrew! To install HomeBrew, simply copy/paste the following command into your Terminal:
Note
You can confirm the HomeBrew installed correctly by running the command: below:
- You’ve installed HomeBrew! Now let’s install the Python 3, the reason why you’re here. To install the latest version of Python, just copy/paste the following command into your Terminal:
Note
You can confirm which version of Python was installed all by running the command below (the exact same command you tried earlier in this guide). It should show up as follows:
- Finally, let’s run our new Python 3. Simply enter
python3
.
Voila! You have now installed Python 3 successfully if you see something similar in your Terminal:
Bonus
•If you want to exit, type
exit()
and then hit your Return button on your keyboard. You can also hit both Control and D keys at the same time instead of the Return key._nb_ext_conf
•Remember I mentioned you can run both your new Python 3 alongside your old Python 2? Yup. Simply type
python
into the Terminal to run with Python 2.