Sunday, December 27, 2015

Anaconda Environment and VirtualEnv Management

Anaconda Python from Continuum is a great tool. It is easy to install and get rid of a lot of the headache of package installation and management.  It is one of the reasons Python has a big footprint in the Scientific Computing and Data Science circle, in my opinion. I enjoy their one-installer-for-all-platform especially and happily traded in my 'pip' commands for 'conda' commands (for more information click here). Anaconda is my default Python interpreter on multiple machines.

There is only one complain, working with Python VirtualEnv is different when you have Anaconda Python as your default Python interpreter. Doing a quick search for 'Anaconda Python VirtualEnv' shows a lot of frustration amongst others. Conda places emphasis on reproducibility as all scientific research should, so their recommended way of managing environment is to use the 'conda env' commands.

I don't claim the following is correct, but they work for me.

***** Using the Good Old VirtualEnv for Learning *****

Currently I am going thru RealPython's courses (which are excellent, by the way), and want to create quick VirtualEnv to separate the different packages used in different lessons.

- Find out your Python interpreter path and specify it when creating virtualenv

MacBook-Air:my_code echou$ virtualenv -p /usr/bin/python2.7 test
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in test/bin/python
Installing setuptools, pip, wheel...done.
MacBook-Air:my_code echou$ source test/bin/activate
(test)MacBook-Air:my_code echou$
(test)MacBook-Air:my_code echou$ deactivate

MacBook-Air:my_code echou$ 

***** Use Conad Env for more Permanent Projects *****

I also intend to keep a few Flask environment active for some other projects, which I have elected to use the Conda environments. 

Here are some helpful links: 

http://conda.pydata.org/docs/using/envs.html #Managing Anaconda environments



MacBook-Air:my_code echou$ conda env --help
usage: conda-env [-h] {attach,create,export,list,remove,upload,update} ...

positional arguments:
  {attach,create,export,list,remove,upload,update}
    attach              Embeds information describing your conda environment
                        into the notebook metadata
    create              Create an environment based on an environment file
    export              Export a given environment
    list                List the Conda environments
    remove              Remove an environment
    upload              Upload an environment to anaconda.org
    update              Update the current environment based on environment
                        file

optional arguments:
  -h, --help            Show this help message and exit.

my_code echou$ conda create --name TEST2 ipython (click on the link above for Anaconda package list)
Fetching package metadata: ....
Solving package specifications: ...............
Package plan for installation in environment <locaion>/anaconda/envs/TEST2:

The following NEW packages will be INSTALLED:

    appnope:          0.1.0-py27_0
    decorator:        4.0.6-py27_0
    ipython:          4.0.1-py27_0
    ipython_genutils: 0.1.0-py27_0
    openssl:          1.0.2d-0
    path.py:          8.1.2-py27_1
    pexpect:          3.3-py27_0
    pickleshare:      0.5-py27_0
    pip:              7.1.2-py27_0
    python:           2.7.11-0
    python.app:       1.2-py27_4
    readline:         6.2-2
    setuptools:       19.1.1-py27_0
    simplegeneric:    0.8.1-py27_0
    sqlite:           3.8.4.1-1
    tk:               8.5.18-0
    traitlets:        4.0.0-py27_0
    wheel:            0.26.0-py27_1
    zlib:             1.2.8-0

Proceed ([y]/n)? y

Linking packages ...
[      COMPLETE      ]|##################################################################################################################| 100%
#
# To activate this environment, use:
# $ source activate TEST2
#
# To deactivate this environment, use:
# $ source deactivate
#

my_code echou$ source activate TEST2
discarding <path>/anaconda/bin from PATH
prepending <path>/anaconda/envs/TEST2/bin to PATH
(TEST2)my_code echou$ source deactivate
discarding <path>/anaconda/envs/TEST2/bin from PATH
my_code echou$
*****

So far it works for me, if I find any problems or issues down the line I will update this post. 

Happy Coding! 




3 comments:

  1. Thank you very much for the sharing! COOL..
    Time management

    ReplyDelete
  2. MB6-896 exam dumps - MB6-896 Dumps - PDF (New 2018) Actual Microsoft MB6-896 Exam

    ReplyDelete
  3. An SEO expert can manually scour your site checking that links go to the right place, your images are of decent quality and your site is aesthetically pleasing. As first impressions are quite important to people, your website should be up to standard and easy to use. rps org

    ReplyDelete