官术网_书友最值得收藏!

Setting up Anaconda

Anaconda is a free Python distribution for data analysis and scientific computing. It has its own package manager, conda. The distribution includes more than 200 Python packages, which makes it very convenient. For casual users, the Miniconda distribution may be the better choice. Miniconda contains the conda package manager and Python. The technical editors use Anaconda, and so do I. But don't worry, I will describe in this book alternative installation instructions for readers who are not using Anaconda. In this recipe, we will install Anaconda and Miniconda and create a virtual environment.

Getting ready

The procedures to install Anaconda and Miniconda are similar. Obviously, Anaconda requires more disk space. Follow the instructions on the Anaconda website at http://conda.pydata.org/docs/install/quick.html (retrieved Mar 2016). First, you have to download the appropriate installer for your operating system and Python version. Sometimes, you can choose between a GUI and a command-line installer. I used the Python 3.4 installer, although my system Python version is v2.7. This is possible because Anaconda comes with its own Python. On my machine, the Anaconda installer created an anaconda directory in my home directory and required about 900 MB. The Miniconda installer installs a miniconda directory in your home directory.

How to do it...

  1. Now that Anaconda or Miniconda is installed, list the packages with the following command:
    $ conda list
    
  2. For reproducibility, it is good to know that we can export packages:
    $ conda list --export
    
  3. The preceding command prints packages and versions on the screen, which you can save in a file. You can install these packages with the following command:
    $ conda create -n ch1env --file <export file>
    

    This command also creates an environment named ch1env.

  4. The following command creates a simple testenv environment:
    $ conda create --name testenv python=3
    
  5. On Linux and Mac OS X, switch to this environment with the following command:
    $ source activate testenv
    
  6. On Windows, we don't need source. The syntax to switch back is similar:
    $ [source] deactivate
    
  7. The following command prints export information for the environment in the YAML (explained in the following section) format:
    $ conda env export -n testenv
    
  8. To remove the environment, type the following (note that even after removing, the name of the environment still exists in ~/.conda/environments.txt):
    $ conda remove -n testenv --all
    
  9. Search for a package as follows:
    $ conda search numpy
    

    In this example, we searched for the NumPy package. If NumPy is already present, Anaconda shows an asterisk in the output at the corresponding entry.

  10. Update the distribution as follows:
    $ conda update conda
    

There's more...

The .condarc configuration file follows the YAML syntax.

Note

YAML is a human-readable configuration file format with the extension .yaml or .yml. YAML was initially released in 2011, with the latest release in 2009. The YAML homepage is at http://yaml.org/ (retrieved July 2015).

You can find a sample configuration file at http://conda.pydata.org/docs/install/sample-condarc.html (retrieved July 2015). The related documentation is at http://conda.pydata.org/docs/install/config.html (retrieved July 2015).

See also

主站蜘蛛池模板: 湖州市| 台江县| 子长县| 英超| 临颍县| 东乌珠穆沁旗| 枞阳县| 曲水县| 淮北市| 正安县| 太原市| 城市| 九江市| 增城市| 大悟县| 乐昌市| 夏邑县| 五寨县| 和龙市| 龙岩市| 阳高县| 漳浦县| 高青县| 五原县| 德州市| 泾源县| 苏州市| 承德县| 赤壁市| 会昌县| 罗江县| 盐亭县| 色达县| 获嘉县| 云梦县| 武胜县| 观塘区| 林芝县| 宁陵县| 黑河市| 五常市|