How to do it...

As an example, lets install scikit-image, a package for image processing available at the site http://scikit-image.org:

To install scikit-image, first update conda and Anaconda by running the following two commands in your Terminal:

conda update conda
conda update anaconda

Now, scikit-image can be installed by running the following command at the system prompt:

conda install scikit-image

After the installation is finished, use a text editor to create a file called skimage_test.py containing the following code:

from skimage import data, io, filters

image = data.coins()
edges = filters.sobel(image)
io.imshow(edges)
io.show()

This code first constructs an image object from one of the sample images contained in scikit-image, which in this example is a photograph of a collection of old coins. It then applies a Sobel filter, which emphasizes the edges of objects present in the image. Finally, it displays the image of the detected coin edges.

Save the file and run the script by entering the following statement at the command line:

python3 skimage_test.py

Once the script runs, an image of the coin edges is displayed. Close the image to exit the script.

Let's now suppose that you don't need scikit-image any longer. It is easy to uninstall the package with conda using the following command:

conda uninstall scikit-image

If, after uninstalling, you attempt to run the skimage_test.py script, you will get an error message stating that Python can't import the skimage library.

Finally, what if a package is not available in Anaconda? In this case, it is still possible to install the package with pip, as outlined in the next section.

An alternative to installing packages directly in the global Anaconda distribution is to create a virtual environment with conda. Later in this chapter, we present several recipes for creating virtual environments with different requirements.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset