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

Creating a conda environment with a different version of a package

We often need to run code that is not compatible with a particular version of a package. In this situation, it is useful to use conda to find out what version of a package is currently installed. For instance, to get information about which version of the numpy package is being used at the moment, we can execute the command shown as follows at the system prompt:

conda info numpy

On my computer, this outputs the following information:

numpy 1.12.1 py36_nomkl_0
file name : numpy-1.12.1-py36_nomkl_0.tar.bz2
name : numpy
version : 1.12.1

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

Let's now suppose that we have a legacy package that depends on an earlier version of NumPy. For example, let's assume we need version 1.7 of NumPy. We can check what versions of NumPy are available in the Anaconda repository with the following command:

conda search numpy

Running this command will produce a long list, in which we find the following information:

...  
1.7.1 py33_0 defaults
...
1.7.1 py33_2 defaults
...

conda shows several available packages of NumPy, some of them compatible with Python 3. Let's now create an environment that has the older version of NumPy installed. Start by creating the new environment with the following command:

conda create --name numpy17 python=3 numpy=1.7

Notice that we specify the required versions for both Python and NumPy. conda will then display the following information about the environment to be created:

The following NEW packages will be INSTALLED:
numpy: 1.7.1-py33_2
openssl: 1.0.1k-1
pip: 8.0.3-py33_0
python: 3.3.5-3
readline: 6.2-2
...

Notice that conda will downgrade the version of Python in the new environment. conda packages are carefully designed to prevent incompatibilities. Go ahead and accept the changes to start the installation.

When the installation is complete, activate the new package. On Linux and macOS, we do this with with the following command:

source activate numpy17

On Windows, use the following command to activate the environment:

activate numpy17

After the environment is activated, we can install any packages that require version 1.7 of NumPy.

When we have finished working on the project, we need to deactivate the environment. On Linux and macOS, we use the following command:

source deactivate numpy17

On Windows, the command to deactivate an environment is as follows:

deactivate numpy17
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