Tuesday, July 26, 2016

Introduction to Conda Workshop

I went thru the Conda Workshop this past Saturday, July 23rd sponsored by Puget Sound Programming Python Group and FlowRoute. The course was taught by Jasmine Sandhu and Chris Barker. Jasmine talked about the basics of the Conda package management system while Chris talked about Conda Recipes.

While both topics are very interesting, the introduction to Conda served one step further from my previous understanding of this tool. To be honest, I have been using Virtualenv and Pip most of the time mostly because of familiarities, but this workshop game me some new perspectives about the tool.

The introductory session notebook link below, it is worth a read if you are interested in what the tool is about:
https://github.com/sandhujasmine/CondaWorkshop/blob/master/IntroConda.ipynb

Basically, I think there are three reasons to use Conda over virtualenv/pip:

1. Separation of the binary packages such as NumPy.
2. It is both a package manager (pip) and environment manager (virtualenv). Therefore you can have one file that takes care of environment separation and package installation (think requirements.txt).
3. Channels. It is like rolling a GitHub repo natively into Python, available both in public (free) and private (paid) repo.

Here are some pictures from the session (I particularly liked the phone booth):


I wont repeat anything that is in the IPython notebook, you should check out that link since she is the expert. However, here is a sample workflow that I worked on (flask-ask):

1. Create Env

MacBook-Air:Alexa echou$ conda create -n flask-ask-temp1 python=2.7
Fetching package metadata .......
Solving package specifications: ..........

Package plan for installation in environment /Users/echou/anaconda/envs/flask-ask-temp1:

The following NEW packages will be INSTALLED:

    openssl:    1.0.2h-1
    pip:        8.1.2-py27_0
    python:     2.7.12-1
    readline:   6.2-2
    setuptools: 23.0.0-py27_0
    sqlite:     3.13.0-0
    tk:         8.5.18-0
    wheel:      0.29.0-py27_0
    zlib:       1.2.8-3

Proceed ([y]/n)? y

Linking packages ...
[      COMPLETE      ]|########################################################################| 100%
#
# To activate this environment, use:
# $ source activate flask-ask-temp1
#
# To deactivate this environment, use:
# $ source deactivate
#
MacBook-Air:Alexa echou$

2. Activate Environment

MacBook-Air:Alexa echou$ source activate flask-ask-temp1

3. Install a conda package

(flask-ask-temp1) MacBook-Air:Alexa echou$ conda install numpy
Fetching package metadata .......
Solving package specifications: ..........

Package plan for installation in environment /Users/echou/anaconda/envs/flask-ask-temp1:

The following NEW packages will be INSTALLED:

    mkl:   11.3.3-0
    numpy: 1.11.1-py27_0

Proceed ([y]/n)? y

Linking packages ...
[      COMPLETE      ]|########################################################################| 100%
(flask-ask-temp1) MacBook-Air:Alexa echou$

4. Install a package that is NOT available thru Conda:

(flask-ask-temp1) MacBook-Air:Alexa echou$ pip install flask-ask
Collecting flask-ask
Collecting PyYAML (from flask-ask)
Collecting six (from flask-ask)
  Using cached six-1.10.0-py2.py3-none-any.whl

5. Testing

(flask-ask-temp1) MacBook-Air:Alexa echou$ python
Python 2.7.12 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:43:17)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> from flask_ask import Ask
>>> dir()
['Ask', '__builtins__', '__doc__', '__name__', '__package__']
>>> exit()
(flask-ask-temp1) MacBook-Air:Alexa echou$

6. Deactivate

(flask-ask-temp1) MacBook-Air:Alexa echou$ source deactivate
MacBook-Air:Alexa echou$

7. Delete the Env

(flask-ask-temp1) MacBook-Air:Alexa echou$ source deactivate
MacBook-Air:Alexa echou$ conda remove -n flask-ask-temp1 --all

Package plan for package removal in environment /Users/echou/anaconda/envs/flask-ask-temp1:

The following packages will be REMOVED:

    mkl:        11.3.3-0
    numpy:      1.11.1-py27_0
    openssl:    1.0.2h-1
    pip:        8.1.2-py27_0
    python:     2.7.12-1
    readline:   6.2-2
    setuptools: 23.0.0-py27_0
    sqlite:     3.13.0-0
    tk:         8.5.18-0
    wheel:      0.29.0-py27_0
    zlib:       1.2.8-3

Proceed ([y]/n)? Y

Unlinking packages ...
[      COMPLETE      ]|########################################################################| 100%
MacBook-Air:Alexa echou$

There you have it, one step further to manage your Python work environment.

Leave me a comment for your thoughts! Happy Coding!





No comments:

Post a Comment