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
Conferences
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

Using conda environments to run different versions of Python

Another situation that comes up often is the need to test a package in a different version of Python. conda makes it easy to create a suitable environment. In this recipe, we will show you how to create and use environments with version 2.7 of Python.

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. Create the new environment with the following command:
conda create --name python27 python=2.7

conda will display information about the changes and ask for confirmation. Go ahead and enter yes to accept the environment creation.

  1. To activate the environment on Linux and macOS, use the following command:
source activate python27
  1. On Windows, the command to activate an environment is as follows:
activate python27
  1. Let's now test the new environment. Start Python in the usual way after activating the environment. Notice that in the startup message, it should state that version 2.7 of Python is being run. Now run the following statement in the Python prompt:
zip([['a','b'],[1,2]])
  1. This will produce the following output:
[('a', 1), ('b', 2)]
  1. This confirms that we are running Python 2, since in Python 3 the zip() function returns an iterator object instead of a list. To leave the Python shell, run the following in the Python prompt:
quit()
  1. When done with the environment, deactivate it by running the following command on Linux and macOS:
source deactivate python27
  1. On Windows, run the following:
deactivate python27
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