Posted on February 25, 2017 by Paul
Updated 26 January 2020
This is a short tutorial about installing Python 3 with NumPy, SciPy and Matplotlib on Windows.
On Ubuntu and other Debian-based Linux systems, you would have to install the ruby-dev and build-essential packages in addition to ruby. Install or update Once you have Ruby and the build tools installed, the command below can be used to install SequenceServer. Install NumPy, SciPy, Matplotlib with Python 3 on Windows Posted on February 25, 2017 by Paul. Updated 26 January 2020. This is a short tutorial about installing Python 3 with NumPy, SciPy and Matplotlib on Windows.
There is also a video version of this tutorial:
We’ll start by installing the latest stable version of Python 3, which at the time of this writing is 3.8. Head over to https://www.python.org/downloads/ and download the installer. The default Python Windows installer is 32 bits and this is what I will use in this article. If you need the 64 bits version of Python, check the Looking for a specific release? section from the above page.
Start the installer and select Customize installation. On the next screen leave all the optional features checked. Finally, on the Advanced Options screen make sure to check Install for all users, Add Python to environment variables and Precompile standard library. Optionally, you can customize the install location. I’ve used C:Python38. You should see something like this:
Press the Install button and in a few minutes, depending on the speed of your computer, you should be ready. On the last page of the installer, you should also press the Disable path length limit:
Now, to check if Python was correctly installed, open a Command Prompt (or a PowerShell) window. Press and hold the SHIFT key and right click with your mouse somewhere on your desktop, select Open command window here. Alternatively, on Windows 10, use the bottom left search box to search for cmd.
Write python in the command window and press Enter, you should see something like this:
Exit from the Python interpreter by writing quit() and pressing the Enter key.
Now, open a cmd window like before. Use the next set of commands to install NumPy, SciPy and Matplotlib:
After each of the above commands you should see Successfully installed ….
Launch Python from a cmd window and check the version of Scipy, you should see something like this:
Let’s try something a bit more interesting now, let’s plot a simple function with Matplotlib. First, we’ll import SciPy and Matplotlib with:
Next, we can define some points on the (0, 1) interval with:
Now, let’s plot a parabola defined by the above interval:
You should see something like this:
If you want to learn more about Python and Matplotlib, I recommend reading Python Crash Course by Eric Matthes. The book is intended for beginners, but has a nice Data Visualization intro to Matplotlib chapter:
Another good Python book, for more advanced users, which also uses Matplotlib for some of the book projects is Python Playground by Mahesh Venkitachalam:
Next Tutorial:OpenCV configuration options reference
There are two ways of installing OpenCV on your machine: download prebuilt version for your platform or compile from sources.
In many cases you can find prebuilt version of OpenCV that will meet your needs.
Packages by OpenCV core team
Packages for Android, iOS and Windows built with default parameters and recent compilers are published for each release, they do not contain opencv_contrib modules.
- GitHub releases: https://github.com/opencv/opencv/releases
- SourceForge.net: https://sourceforge.net/projects/opencvlibrary/files/
Third-party packages
Other organizations and people maintain their own binary distributions of OpenCV. For example:
- System packages in popular Linux distributions (https://pkgs.org/search/?q=opencv)
- PyPI (https://pypi.org/search/?q=opencv)
- Conda (https://anaconda.org/search?q=opencv)
- Conan (https://github.com/conan-community/conan-opencv)
- vcpkg (https://github.com/microsoft/vcpkg/tree/master/ports/opencv)
- NuGet (https://www.nuget.org/packages?q=opencv)
- Brew (https://formulae.brew.sh/formula/opencv)
- Maven (https://search.maven.org/search?q=opencv)
It can happen that existing binary packages are not applicable for your use case, then you'll have to build custom version of OpenCV by yourself. This section gives a high-level overview of the build process, check tutorial for specific platform for actual build instructions.
OpenCV uses CMake build management system for configuration and build, so this section mostly describes generalized process of building software with CMake.
Step 0: Prerequisites
Install C++ compiler and build tools. On *NIX platforms it is usually GCC/G++ or Clang compiler and Make or Ninja build tool. On Windows it can be Visual Studio IDE or MinGW-w64 compiler. Native toolchains for Android are provided in the Android NDK. XCode IDE is used to build software for OSX and iOS platforms.
Install CMake from the official site or some other source.
Get other third-party dependencies: libraries with extra functionality like decoding videos or showing GUI elements; libraries providing optimized implementations of selected algorithms; tools used for documentation generation and other extras. Check OpenCV configuration options reference for available options and corresponding dependencies.
Step 1: Get software sources
Typical software project consists of one or several code repositories. OpenCV have two repositories with code: opencv - main repository with stable and actively supported algorithms and opencv_contrib which contains experimental and non-free (patented) algorithms; and one repository with test data: opencv_extra.
You can download a snapshot of repository in form of an archive or clone repository with full history.
To download snapshot archives:
- Go to https://github.com/opencv/opencv/releases and download 'Source code' archive from any release.
- (optionally) Go to https://github.com/opencv/opencv_contrib/releases and download 'Source code' archive for the same release as opencv
- (optionally) Go to https://github.com/opencv/opencv_extra/releases and download 'Source code' archive for the same release as opencv
- Unpack all archives to some location
To clone repositories run the following commands in console (gitmust be installed):
Osx Install Gcc
- Note
- If you want to build software using more than one repository, make sure all components are compatible with each other. For OpenCV it means that opencv and opencv_contrib repositories must be checked out at the same tag or that all snapshot archives are downloaded from the same release.
- When choosing which version to download take in account your target platform and development tools versions, latest versions of OpenCV can have build problems with very old compilers and vice versa. We recommend using latest release and fresh OS/compiler combination.
Step 2: Configure
At this step CMake will verify that all necessary tools and dependencies are available and compatible with the library and will generate intermediate files for the chosen build system. It could be Makefiles, IDE projects and solutions, etc. Usually this step is performed in newly created build directory:
- Note
cmake-gui
application allows to see and modify available options using graphical user interface. See https://cmake.org/runningcmake/ for details.
Step 3: Build
Osx Install Gcc Link
During build process source files are compiled into object files which are linked together or otherwise combined into libraries and applications. This step can be run using universal command:
... or underlying build system can be called directly:
Step 3: Install
Osx Install Gcc Homebrew
During installation procedure build results and other files from build directory will be copied to the install location. Default installation location is /usr/local
on UNIX and C:/Program Files
on Windows. This location can be changed at the configuration step by setting CMAKE_INSTALL_PREFIX
option. To perform installation run the following command:
Osx Install Gcc.8
- Note
- This step is optional, OpenCV can be used directly from the build directory.
- If the installation root location is a protected system directory, so the installation process must be run with superuser or administrator privileges (e.g.
sudo cmake ...
).