Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
SciPy Recipes

You're reading from   SciPy Recipes A cookbook with over 110 proven recipes for performing mathematical and scientific computations

Arrow left icon
Product type Paperback
Published in Dec 2017
Publisher Packt
ISBN-13 9781788291460
Length 386 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
V Kishore Ayyadevara V Kishore Ayyadevara
Author Profile Icon V Kishore Ayyadevara
V Kishore Ayyadevara
Ruben Oliva Ramos Ruben Oliva Ramos
Author Profile Icon Ruben Oliva Ramos
Ruben Oliva Ramos
Luiz Felipe Martins Luiz Felipe Martins
Author Profile Icon Luiz Felipe Martins
Luiz Felipe Martins
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Getting to Know the Tools FREE CHAPTER 2. Getting Started with NumPy 3. Using Matplotlib to Create Graphs 4. Data Wrangling with pandas 5. Matrices and Linear Algebra 6. Solving Equations and Optimization 7. Constants and Special Functions 8. Calculus, Interpolation, and Differential Equations 9. Statistics and Probability 10. Advanced Computations with SciPy

Installing optional packages with conda

Sooner or later, you will need a package that is not installed by default in your Anaconda distribution.

If you are using the Anaconda distribution, this recipe describes the preferred method of installing and uninstalling packages. Anaconda is built on top of conda, a flexible and easy-to-use package manager.

Anaconda allows direct access to vast collections of add-on packages. For example, it makes it easy to install SciKits, which are SciPy packages developed by independent developers that are not part of the main distribution. A complete list of SciKits can be found at the following site: http://scikits.appspot.com/scikits.

Getting ready

This recipe assumes that you have a working installation of Anaconda. If you don't, follow the recipe for installing Anaconda for your operating system presented previously in this chapter.

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.
You have been reading a chapter from
SciPy Recipes
Published in: Dec 2017
Publisher: Packt
ISBN-13: 9781788291460
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image