- Install Scipy Ubuntu 14.04
- Install Scipy Ubuntu Python3
- Python Install Scipy Ubuntu
- Install Numpy Python Ubuntu
- Install Scipy Ubuntu Pip
Over the past two years running the PyImageSearch blog, I’ve authored two tutorials detailing the required steps to install OpenCV (with Python bindings) on Ubuntu. You can find the two tutorials here:
I am trying to install scipy on a Ubuntu 15.04 virtual box using the command pip install scipy During the installation, however, I get the following error: error: library dfftpack has Fortran so. NumPy, SciPy, Pandas, and Matplotlib are fundamental scientific computing and visualization packages with Python. Scikit-learn is a simple and efficient package for data mining and analysis in Python.
However, with support of Ubuntu 14.04 winding down and Ubuntu 16.04 set as the next LTS (with support until April 2021), I thought it would be appropriate to create a new, updated Ubuntu + OpenCV install tutorial.
Inside this tutorial, I will document, demonstrate, and provide detailed steps to install OpenCV 3 on Ubuntu 16.04 with either Python 2.7 or Python 3.5 bindings.
Furthermore, this document has been fully updated from my previous Ubuntu 14.04 tutorials to use the latest, updated packages from the apt-get repository.
To learn how to install OpenCV on your Ubuntu 16.04 system, keep reading.
Note: Don’t care about Python bindings and simply want OpenCV installed on your system (likely for C++ coding)? No worries, this tutorial will still work for you. Follow along with the instructions and perform the steps — by the end of this article you’ll have OpenCV installed on your system. From there, just ignore the Python bindings and proceed as usual.
Ubuntu 16.04: How to install OpenCV
Before we get into this tutorial, I want to mention that Ubuntu 16.04 actually ships out-of-the-box with both Python 2.7 and Python 3.5 installed. The actual versions (as of 24 October 2016) are:
- Python 2.7.12 (used by default when you type python in your terminal).
- Python 3.5.2 (can be accessed via the python3 command).
Again, it’s worth repeating that Python 2.7 is still the default Python version used by Ubuntu. There are plans to migrate to Python 3 and use Python 3 by default; however, as far as I can tell, we are still a long way from that actually becoming a reality.
In either case, this tutorial will support both Python 2.7 and Python 3. I’ve highlighted the steps that require you to make a decision regarding which version of Python you would like to use. Make sure you are consistent with your decision, otherwise you will inevitably run into compile, linking, and import errors.
Regarding which Python version you should use…I’m not getting into that argument. I’ll simply say that you should use whichever version of Python you are comfortable with and use on a daily basis. Keep in mind that Python 3 is the future — but also keep in mind that porting Python 2.7 code to Python 3 isn’t terribly challenging either once you understand the differences between the Python versions. And as far as OpenCV goes, OpenCV 3 doesn’t care which version of Python you’re using: the bindings will work just the same.
All that said, let’s get started installing OpenCV with Python bindings on Ubuntu 16.04.
Step #1: Install OpenCV dependencies on Ubuntu 16.04
Most (in fact, all) steps in this tutorial will be accomplished by using your terminal. To start, open up your command line and update the apt-get package manager to refresh and upgrade and pre-installed packages/libraries:
2 | $sudo apt-getupgrade |
Next, let’s install some developer tools:
2 | $wget https://bootstrap.pypa.io/get-pip.py |
I’ve mentioned this in every single OpenCV + Python install tutorial I’ve ever done, but I’ll say it again here today: I’m a huge fan of both virtualenv and virtualenvwrapper. These Python packages allow you to create separate, independent Python environments for each project that you are working on.
In short, using these packages allows you to solve the “Project X depends on version 1.x, but Project Y needs 4.x dilemma. A fantastic side effect of using Python virtual environments is that you can keep your system Python neat, tidy, and free from clutter.
While you can certainly install OpenCV with Python bindings without Python virtual environments, I highly recommend you use them as other PyImageSearch tutorials leverage Python virtual environments. I’ll also be assuming that you have both virtualenv and virtualenvwrapper installed throughout the remainder of this guide.
If you would like a full, detailed explanation on why Python virtual environments are a best practice, you should absolutely give this excellent blog post on RealPython a read. I also provide some commentary on why I personally prefer Python virtual environments in the first half of this tutorial.
Again, let me reiterate that it’s standard practice in the Python community to be leveraging virtual environments of some sort, so I suggest you do the same:
2 | $echo-e'n# virtualenv and virtualenvwrapper'>>~/.bashrc $echo'export WORKON_HOME=$HOME/.virtualenvs'>>~/.bashrc $echo'source /usr/local/bin/virtualenvwrapper.sh'>>~/.bashrc |
After editing our ~/.bashrc file, we need to reload the changes:
Note:Calling source on .bashrc only has to be done once for our current shell session. Anytime we open up a new terminal, the contents of .bashrc will be automatically executed (including our updates).
Now that we have installed virtualenv and virtualenvwrapper , the next step is to actually create the Python virtual environment — we do this using the mkvirtualenv command.
But before executing this command, you need to make a choice: Do you want to use Python 2.7 or Python 3?
The outcome of your choice will determine which command you run in the following section.
Creating your Python virtual environment
If you decide to use Python 2.7, use the following command to create a Python 2.7 virtual environment:
Otherwise, use this command to create a Python 3 virtual environment:
Regardless of which Python command you decide to use, the end result is that we have created a Python virtual environment named cv (short for “computer vision”).
You can name this virtual environment whatever you like (and create as many Python virtual environments as you want), but for the time bing, I would suggest sticking with the cv name as that is what I’ll be using throughout the rest of this tutorial.
Verifying that you are in the “cv” virtual environment
If you ever reboot your Ubuntu system; log out and log back in; or open up a new terminal, you’ll need to use the workon command to re-access your cv virtual environment. An example of the workon command follows:
To validate that you are in the cv virtual environment, simply examine your command line — if you see the text (cv) preceding your prompt, then you are in the cv virtual environment:
Figure 1: Make sure you see the “(cv)” text on your prompt, indicating that you are in the cv virtual environment.
Otherwise, if you do not see the cv text, then you are not in the cv virtual environment:
Install Scipy Ubuntu 14.04
Figure 2: If you do not see the “(cv)” text on your prompt, then you are not in the cv virtual environment and need to run the “workon” command to resolve this issue.
To access the cv virtual environment simply use the workon command mentioned above.
Install NumPy into your Python virtual environment
The final step before we compile OpenCV is to install NumPy, a Python package used for numerical processing. To install NumPy, ensure you are in the cv virtual environment (otherwise NumPy will be installed into the system version of Python rather than the cv environment). From there execute the following command:
Step #4: Configuring and compiling OpenCV on Ubuntu 16.04
At this point, all of our necessary prerequisites have been installed — we are now ready to compile and OpenCV!
But before we do that, double-check that you are in the cv virtual environment by examining your prompt (you should see the (cv) text preceding it), and if not, use the workon command:
After ensuring you are in the cv virtual environment, we can setup and configure our build using CMake: