Instalacija: Numpy, Matplotlib, SciPy, OpenCV

This is a short article about installing NumPy, SciPy, Matplotlib and OpenCV on the latest Ubuntu LTS, which at the time of this writing is 18.04. Ubuntu 18.04 comes with Python 3.6.5. (Source:

Let’s start by making sure we have an updated system:
sudo apt update
sudo apt upgrade

Now, let’s install NumPy, SciPy and Matplotlib:
sudo apt install python3-numpy python3-scipy python3-matplotlib

If you need OpenCV, you can install it with:
sudo apt install python3-opencv

Many useful Python libraries can be installed from, let’s make sure we have pip on our system:
sudo apt install python3-pip

If you need to install a library from, for example the Python Imaging Library Pillow, you can do it with:

pip3 install Pillow

We can test ScipPy and Matplotlib, by writing a short test program:
import scipy as sp
import matplotlib.pylab as plt

t = sp.arrange(0, 10, 1/100)
plt.plot(t, sp.sin(1.7 * 2 * sp.pi * t) + sp.sin(1.9 * 2 * sp.pi * t))

Save the above code as and run it with:

You should see something like in the next figure:
We can write a small test program that will print the OpenCV version, load an image from the disk, convert the image to gray and show the result. Start by downloading the next image:

Save it as clouds.jpg. In the same folder where you’ve saved the above image, create a new file and write the next code: 
import cv2  

print("OpenCV version:") 

img = cv2.imread("clouds.jpg") 
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 

cv2.imshow("Over the Clouds", img) 
cv2.imshow("Over the Clouds - gray", gray) 
cv2.waitKey(0) 13 cv2.destroyAllWindows() 

Run the code with:

(You can close the two windows by pressing ESC!) You should see something like in the next figure:

Nema komentara:

Pokreće Blogger.