Book Image

SciPy Recipes

By : V Kishore Ayyadevara, Ruben Oliva Ramos
Book Image

SciPy Recipes

By: V Kishore Ayyadevara, Ruben Oliva Ramos

Overview of this book

With the SciPy Stack, you get the power to effectively process, manipulate, and visualize your data using the popular Python language. Utilizing SciPy correctly can sometimes be a very tricky proposition. This book provides the right techniques so you can use SciPy to perform different data science tasks with ease. This book includes hands-on recipes for using the different components of the SciPy Stack such as NumPy, SciPy, matplotlib, and pandas, among others. You will use these libraries to solve real-world problems in linear algebra, numerical analysis, data visualization, and much more. The recipes included in the book will ensure you get a practical understanding not only of how a particular feature in SciPy Stack works, but also of its application to real-world problems. The independent nature of the recipes also ensure that you can pick up any one and learn about a particular feature of SciPy without reading through the other recipes, thus making the book a very handy and useful guide.
Table of Contents (11 chapters)

Creating a virtual environment for development with conda 

This recipe demonstrates how to set up an environment that is a clone of the current Anaconda installation. One possible use of this procedure is to set up an environment when we start the development of a new project.

Getting ready

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

How to do it...

  1. Start by opening a Terminal window and running the following commands:
conda update conda
conda update anaconda

These commands update both conda and Anaconda to the most recent versions. This is always recommended before creating a new environment.

  1. Next, run the following line to create a new environment named myenv:
conda create --name myenv
  1. You will be asked for confirmation and conda will then create the new environment. We now need to activate the new environment. For Linux and macOS, run the following command in the terminal:
source activate myenv
  1. In Windows, run the following:
activate myenv
  1. Notice that the command line changes to reflect the active environment, as shown in the following example:
(myenv) computer:~ username
  1. To confirm that the new environment was created, we can execute the following command:
conda info --envs
  1. This command now produces the following output:
# conda environments:
#
myenv * /Users/username/anaconda/envs/myenv
root /Users/username/anaconda

Notice that the currently active environment is marked with an asterisk.

  1. We can now install packages in the active environment without interfering with the original Python distribution. For example, to install the csvkit package, we use code in the following example:
conda install csvkit
  1. When you are done working in the environment, it is necessary to deactivate it. In Linux and macOS, this is done with the following command:
source deactivate
  1. In Windows, the command to do so is the following:
deactivate
  1. If you decide you don't need the myenv environment any longer, it can be deleted with the following command:
conda remove myenv --all

Note that you cannot remove the currently active environment.