Trang chủ‎ > ‎IT‎ > ‎Programming‎ > ‎Python‎ > ‎

Conda - Anaconda - Miniconda

https://docs.conda.io/en/latest/

Getting started with conda

Conda is a powerful package manager and environment manager that you use with command line commands at the Anaconda Prompt for Windows, or in a terminal window for macOS or Linux.

This 20-minute guide to getting started with conda lets you try out the major features of conda. You should understand how conda works when you finish this guide.

SEE ALSO: Getting started with Anaconda Navigator, a graphical user interface that lets you use conda in a web-like interface without having to enter manual commands. Compare the Getting started guides for each to see which program you prefer.

Before you start

You should have already installed Anaconda.

Contents

TOTAL TIME: 20 MINUTES

Starting conda

Windows

  • From the Start menu, search for and open "Anaconda Prompt."

../_images/anaconda-prompt.png

On Windows, all commands below are typed into the Anaconda Prompt window.

MacOS

  • Open Launchpad, then click the terminal icon.

On macOS, all commands below are typed into the terminal window.

Linux

  • Open a terminal window.

On Linux, all commands below are typed into the terminal window.

Managing conda

Verify that conda is installed and running on your system by typing:

conda --version

Conda displays the number of the version that you have installed. You do not need to navigate to the Anaconda directory.

EXAMPLE: conda 4.4.9

Note

If you get an error message, make sure you closed and re-opened the terminal window after installing, or do it now. Then verify that you are logged into the same user account that you used to install Anaconda or Miniconda.

Update conda to the current version. Type the following:

conda update conda

Conda compares versions and then displays what is available to install.

If a newer version of conda is available, type y to update:

Proceed ([y]/n)? y

Tip

We recommend that you always keep conda updated to the latest version.

Managing environments

Conda allows you to create separate environments containing files, packages and their dependencies that will not interact with other environments.

When you begin using conda, you already have a default environment named base. You don't want to put programs into your base environment, though. Create separate environments to keep your programs isolated from each other.

  1. Create a new environment and install a package in it.

    We will name the environment snowflakes and install the package BioPython. At the Anaconda Prompt or in your terminal window, type the following:

    conda create --name snowflakes biopython
    

    Conda checks to see what additional packages ("dependencies") Biopython will need, and asks if you want to proceed:

    Proceed ([y]/n)? y
    

    Type "y" and press Enter to proceed.

  2. To use, or "activate" the new environment, type the following:

    • Windows: conda activate snowflakes

    • Linux and macOS: conda activate snowflakes

    Note

    conda activate only works on conda 4.6 and later versions.

    For conda versions prior to 4.6, type:

    • Windows: activate snowflakes

    • Linux and macOS: source activate snowflakes

    Now that you are in your snowflakes environment, any conda commands you type will go to that environment until you deactivate it.

  3. To see a list of all your environments, type:

    conda info --envs
    

    A list of environments appears, similar to the following:

    conda environments:
    
        base           /home/username/Anaconda3
        snowflakes   * /home/username/Anaconda3/envs/snowflakes
    

    Tip

    The active environment is the one with an asterisk (*).

  4. Change your current environment back to the default (base): conda activate

    Note

    For versions prior to conda 4.6, use:

    • Windows: activate

    • Linux, macOS: source activate

    Tip

    When the environment is deactivated, its name is no longer shown in your prompt, and the asterisk (*) returns to base. To verify, you can repeat the conda info --envs command.

Managing Python

When you create a new environment, conda installs the same Python version you used when you downloaded and installed Anaconda. If you want to use a different version of Python, for example Python 3.5, simply create a new environment and specify the version of Python that you want.

  1. Create a new environment named "snakes" that contains Python 3.5:

    conda create --name snakes python=3.5
    

    When conda asks if you want to proceed, type "y" and press Enter.

  2. Activate the new environment:

    • Windows: activate snakes

    • Linux, macOS: source activate snakes

  3. Verify that the snakes environment has been added and is active:

    conda info --envs
    

    Conda displays the list of all environments with an asterisk (*) after the name of the active environment:

    # conda environments:
    #
    base                     /home/username/anaconda3
    snakes                *  /home/username/anaconda3/envs/snakes
    snowflakes               /home/username/anaconda3/envs/snowflakes
    

    The active environment is also displayed in front of your prompt in (parentheses) or [brackets] like this:

    (snakes) $
    
  4. Verify which version of Python is in your current environment:

    python --version
    
  5. Deactivate the snakes environment and return to base environment: conda activate

    Note

    For versions prior to conda 4.6, use:
    • Windows: activate

    • Linux, macOS: source activate

Managing packages

In this section, you check which packages you have installed, check which are available and look for a specific package and install it.

  1. To find a package you have already installed, first activate the environment you want to search. Look above for the commands to activate your snakes environment.

  2. Check to see if a package you have not installed named "beautifulsoup4" is available from the Anaconda repository (must be connected to the Internet):

    conda search beautifulsoup4
    

    Conda displays a list of all packages with that name on the Anaconda repository, so we know it is available.

  3. Install this package into the current environment:

    conda install beautifulsoup4
    
  4. Check to see if the newly installed program is in this environment:

    conda list
    

More information

Installation

The fastest way to obtain conda is to install Miniconda, a mini version of Anaconda that includes only conda and its dependencies. If you prefer to have conda plus over 720 open source packages, install Anaconda.

We recommend you install Anaconda for the local user, which does not require administrator permissions and is the most robust type of installation. You can also install Anaconda system wide, which does require administrator permissions.

For information on using our graphical installers for Windows or macOS, see the instructions for installing Anaconda.

System requirements

  • 32- or 64-bit computer.

  • For Miniconda---400 MB disk space.

  • For Anaconda---Minimum 3 GB disk space to download and install.

  • Windows, macOS or Linux.

  • Python 2.7, 3.4, 3.5 or 3.6.

  • pycosat.

  • PyYaml.

  • Requests.

Note

You do not need administrative or root permissions to install Anaconda if you select a user-writable install location.

Regular installation

Follow the instructions for your operating system:

Installing in silent mode

You can use silent installation of Miniconda or Anaconda for deployment or testing or building services such as Travis CI and AppVeyor.

Follow the silent-mode instructions for your operating system:

Installing conda on a system that has other Python installations or packages

You do not need to uninstall other Python installations or packages in order to use conda. Even if you already have a system Python, another Python installation from a source such as the macOS Homebrew package manager and globally installed packages from pip such as pandas and NumPy, you do not need to uninstall, remove, or change any of them before using conda.

Install Anaconda or Miniconda normally, and let the installer add the conda installation of Python to your PATH environment variable. There is no need to set the PYTHONPATH environment variable.

To see if the conda installation of Python is in your PATH variable:

  • On macOS and Linux, open the terminal and run---echo $PATH.

  • On Windows, open an Anaconda Prompt and run---echo %PATH%.

To see which Python installation is currently set as the default:

  • On macOS and Linux, open the terminal and run---which python.

  • On Windows, open an Anaconda Prompt and run---where python.

To see which packages are installed in your current conda environment and their version numbers, in your terminal window or an Anaconda Prompt, run conda list.

Managing conda

Verifying that conda is installed

To verify that conda is installed, in your Terminal window or an Anaconda Prompt, run:

conda --version

Conda responds with the version number that you have installed, such as conda 3.11.0.

If you get an error message, make sure of the following:

  • You are logged into the same user account that you used to install Anaconda or Miniconda.

  • You are in a directory that Anaconda or Miniconda can find.

  • You have closed and re-opened the Terminal window after installing conda.

Determining your conda version

In addition to the conda --version command explained above, you can determine what conda version is installed by running one of the following commands in your Terminal window or an Anaconda Prompt:

conda info

OR

conda -V

Updating conda to the current version

To update conda, in your Terminal window or an Anaconda Prompt, run:

conda update conda

Conda compares versions and reports what is available to install. It also tells you about other packages that will be automatically updated or changed with the update. If conda reports that a newer version is available, type y to update:

Proceed ([y]/n)? y

Managing environments

With conda, you can create, export, list, remove, and update environments that have different versions of Python and/or packages installed in them. Switching or moving between environments is called activating the environment. You can also share an environment file.

Note

There are many options available for the commands described on this page. For details, see Command reference.

Note

conda activate and conda deactivate only work on conda 4.6 and later versions. For conda versions prior to 4.6, run:

  • Windows: activate or deactivate

  • Linux and macOS: source activate or source deactivate

Creating an environment with commands

Tip

By default, environments are installed into the envs directory in your conda directory. Run conda create --help for information on specifying a different path.

Use the terminal or an Anaconda Prompt for the following steps:

  1. To create an environment:

    conda create --name myenv
    

    Note

    Replace myenv with the environment name.

  2. When conda asks you to proceed, type y:

    proceed ([y]/n)?
    

This creates the myenv environment in /envs/. This environment uses the same version of Python that you are currently using because you did not specify a version.

  1. To create an environment with a specific version of Python:

    conda create -n myenv python=3.4
    
  2. To create an environment with a specific package:

    conda create -n myenv scipy
    

    OR:

    conda create -n myenv python
    conda install -n myenv scipy
    
  3. To create an environment with a specific version of a package:

    conda create -n myenv scipy=0.15.0
    

    OR:

    conda create -n myenv python
    conda install -n myenv scipy=0.15.0
    
  4. To create an environment with a specific version of Python and multiple packages:

conda create -n myenv python=3.4 scipy=0.15.0 astroid babel

Tip

Install all the programs that you want in this environment at the same time. Installing 1 program at a time can lead to dependency conflicts.

To automatically install pip or another program every time a new environment is created, add the default programs to the create_default_packages section of your .condarc configuration file. The default packages are installed every time you create a new environment. If you do not want the default packages installed in a particular environment, use the --no-default-packages flag:

conda create --no-default-packages -n myenv python

Tip

You can add much more to the conda create command. For details, run conda create --help.

Creating an environment from an environment.yml file

Use the terminal or an Anaconda Prompt for the following steps:

  1. Create the environment from the environment.yml file:

    conda env create -f environment.yml
    

    The first line of the yml file sets the new environment's name. For details see Creating an environment file manually.

  2. Activate the new environment: conda activate myenv

    Note

    Replace myenv with the environment name.

  3. Verify that the new environment was installed correctly:

    conda list
    

Cloning an environment

Use the terminal or an Anaconda Prompt for the following steps:

You can make an exact copy of an environment by creating a clone of it:

conda create --name myclone --clone myenv

Note

Replace myclone with the name of the new environment. Replace myenv with the name of the existing environment that you want to copy.

To verify that the copy was made:

conda info --envs

In the environments list that displays, you should see both the source environment and the new copy.

Building identical conda environments

You can use explicit specification files to build an identical conda environment on the same operating system platform, either on the same machine or on a different machine.

Use the terminal or an Anaconda Prompt for the following steps:

  1. Run conda list --explicit to produce a spec list such as:

    # This file may be used to create an environment using:
    # $ conda create --name <env> --file <this file>
    # platform: osx-64
    @EXPLICIT
    https://repo.continuum.io/pkgs/free/osx-64/mkl-11.3.3-0.tar.bz2
    https://repo.continuum.io/pkgs/free/osx-64/numpy-1.11.1-py35_0.tar.bz2
    https://repo.continuum.io/pkgs/free/osx-64/openssl-1.0.2h-1.tar.bz2
    https://repo.continuum.io/pkgs/free/osx-64/pip-8.1.2-py35_0.tar.bz2
    https://repo.continuum.io/pkgs/free/osx-64/python-3.5.2-0.tar.bz2
    https://repo.continuum.io/pkgs/free/osx-64/readline-6.2-2.tar.bz2
    https://repo.continuum.io/pkgs/free/osx-64/setuptools-25.1.6-py35_0.tar.bz2
    https://repo.continuum.io/pkgs/free/osx-64/sqlite-3.13.0-0.tar.bz2
    https://repo.continuum.io/pkgs/free/osx-64/tk-8.5.18-0.tar.bz2
    https://repo.continuum.io/pkgs/free/osx-64/wheel-0.29.0-py35_0.tar.bz2
    https://repo.continuum.io/pkgs/free/osx-64/xz-5.2.2-0.tar.bz2
    https://repo.continuum.io/pkgs/free/osx-64/zlib-1.2.8-3.tar.bz2
    
  2. To create this spec list as a file in the current working directory, run:

    conda list --explicit > spec-file.txt
    

    Note

    You can use spec-file.txt as the filename or replace it with a filename of your choice.

    An explicit spec file is not usually cross platform, and therefore has a comment at the top such as # platform: osx-64 showing the platform where it was created. This platform is the one where this spec file is known to work. On other platforms, the packages specified might not be available or dependencies might be missing for some of the key packages already in the spec.

    To use the spec file to create an identical environment on the same machine or another machine:

    conda create --name myenv --file spec-file.txt
    

    To use the spec file to install its listed packages into an existing environment:

    conda install --name myenv --file spec-file.txt
    

    Conda does not check architecture or dependencies when installing from a spec file. To ensure that the packages work correctly, make sure that the file was created from a working environment, and use it on the same architecture, operating system and platform, such as linux-64 or osx-64.

Activating an environment

Activating environments is essential to making the software in the environments work well. Activation entails two primary functions: adding entries to PATH for the environment, and running any activation scripts that the environment may contain. These activation scripts are how packages can set arbitrary environment variables that may be necessary for their operation.

To activate an environment: conda activate myenv

Note

Replace myenv with the environment name or directory path.

Conda prepends the path name myenv onto your system command.

Windows is extremely sensitive to proper activation. This is because the Windows library loader does not support the concept of libraries and executables that know where to search for their dependencies (RPATH). Instead, Windows relies on a standard library search order, defined at https://docs.microsoft.com/en-us/previous-versions/7d83bc18(v=vs.140). If environments are not active, libraries won't get found and there will be lots of errors. HTTP or SSL errors are common errors when the Python in a child environment can't find the necessary OpenSSL library.

Conda itself includes some special workarounds to add its necessary PATH entries. This makes it so that it can be called without activation or with any child environment active. In general, calling any executable in an environment without first activating that environment will likely not work. For the ability to run executables in activated environments, you may be interested in the conda run command.

Deactivating an environment

To deactivate an environment, type: conda deactivate

Conda removes the path name for the currently active environment from your system command.

Note

To simply return to the base environment, it's better to call conda activate with no environment specified, rather than to try to deactivate. If you run conda deactivatefrom your base environment, you may lose the ability to run conda at all. Don't worry, that's local to this shell - you can start a new one.

Determining your current environment

Use the terminal or an Anaconda Prompt for the following steps.

By default, the active environment---the one you are currently using---is shown in parentheses () or brackets [] at the beginning of your command prompt:

(myenv) $

If you do not see this, run:

conda info --envs

In the environments list that displays, your current environment is highlighted with an asterisk (*).

By default, the command prompt is set to show the name of the active environment. To disable this option:

conda config --set changeps1 false

To re-enable this option:

conda config --set changeps1 true

Viewing a list of your environments

To see a list of all of your environments, in your terminal window or an Anaconda Prompt, run:

conda info --envs

OR

conda env list

A list similar to the following is displayed:

conda environments:
myenv                 /home/username/miniconda/envs/myenv
snowflakes            /home/username/miniconda/envs/snowflakes
bunnies               /home/username/miniconda/envs/bunnies

Viewing a list of the packages in an environment

To see a list of all packages installed in a specific environment:

  • If the environment is not activated, in your terminal window or an Anaconda Prompt, run:

    conda list -n myenv
    
  • If the environment is activated, in your terminal window or an Anaconda Prompt, run:

    conda list
    

To see if a specific package is installed in an environment, in your terminal window or an Anaconda Prompt, run:

conda list -n myenv scipy

Using pip in an environment

To use pip in your environment, in your terminal window or an Anaconda Prompt, run:

conda install -n myenv pip
conda activate myenv
pip <pip_subcommand>

Saving environment variables

Conda environments can include saved environment variables.

Suppose you want an environment "analytics" to store both a secret key needed to log in to a server and a path to a configuration file. The sections below explain how to write a script named env_vars to do this on Windows and macOS or Linux.

This type of script file can be part of a conda package, in which case these environment variables become active when an environment containing that package is activated.

You can name these scripts anything you like. However, multiple packages may create script files, so be sure to use descriptive names that are not used by other packages. One popular option is to give the script a name in the form packagename-scriptname.sh, or on Windows, packagename-scriptname.bat.

Windows

  1. Locate the directory for the conda environment in your Anaconda Prompt by running in the command shell %CONDA_PREFIX%.

  2. Enter that directory and create these subdirectories and files:

    cd %CONDA_PREFIX%
    mkdir .\etc\conda\activate.d
    mkdir .\etc\conda\deactivate.d
    type NUL > .\etc\conda\activate.d\env_vars.bat
    type NUL > .\etc\conda\deactivate.d\env_vars.bat
    
  3. Edit .\etc\conda\activate.d\env_vars.bat as follows:

    set MY_KEY='secret-key-value'
    set MY_FILE=C:\path\to\my\file
    
  4. Edit .\etc\conda\deactivate.d\env_vars.bat as follows:

    set MY_KEY=
    set MY_FILE=
    

When you run conda activate analytics, the environment variables MY_KEY and MY_FILE are set to the values you wrote into the file. When you run conda deactivate, those variables are erased.

macOS and Linux

  1. Locate the directory for the conda environment in your terminal window by running in the terminal echo $CONDA_PREFIX.

  2. Enter that directory and create these subdirectories and files:

    cd $CONDA_PREFIX
    mkdir -p ./etc/conda/activate.d
    mkdir -p ./etc/conda/deactivate.d
    touch ./etc/conda/activate.d/env_vars.sh
    touch ./etc/conda/deactivate.d/env_vars.sh
    
  3. Edit ./etc/conda/activate.d/env_vars.sh as follows:

    #!/bin/sh
    
    export MY_KEY='secret-key-value'
    export MY_FILE=/path/to/my/file/
    
  4. Edit ./etc/conda/deactivate.d/env_vars.sh as follows:

    #!/bin/sh
    
    unset MY_KEY
    unset MY_FILE
    

When you run conda activate analytics, the environment variables MY_KEY and MY_FILE are set to the values you wrote into the file. When you run conda deactivate, those variables are erased.

Sharing an environment

You may want to share your environment with someone else---for example, so they can re-create a test that you have done. To allow them to quickly reproduce your environment, with all of its packages and versions, give them a copy of yourenvironment.yml file.

Exporting the environment file

Note

If you already have an environment.yml file in your current directory, it will be overwritten during this task.

  1. Activate the environment to export: conda activate myenv

    Note

    Replace myenv with the name of the environment.

  2. Export your active environment to a new file:

    conda env export > environment.yml
    

    Note

    This file handles both the environment's pip packages and conda packages.

  3. Email or copy the exported environment.yml file to the other person.

Creating an environment file manually

You can create an environment file manually to share with others.

EXAMPLE: A simple environment file:

name: stats
dependencies:
  - numpy
  - pandas

EXAMPLE: A more complex environment file:

name: stats2
channels:
  - javascript
dependencies:
  - python=3.4   # or 2.7
  - bokeh=0.9.2
  - numpy=1.9.*
  - nodejs=0.10.*
  - flask
  - pip:
    - Flask-Testing

You can exclude the default channels by adding nodefaults to the channels list.

channels:
  - javascript
  - nodefaults

This is equivalent to passing the --override-channels option to most conda commands.

Adding nodefaults to the channels list in environment.yml is similar to removing defaults from the channels list in the .condarc file. However, changing environment.yml affects only one of your conda environments while changing .condarcaffects them all.

For details on creating an environment from this environment.yml file, see Creating an environment from an environment.yml file.

Removing an environment

To remove an environment, in your terminal window or an Anaconda Prompt, run:

conda remove --name myenv --all

You may instead use conda env remove --name myenv.

To verify that the environment was removed, in your terminal window or an Anaconda Prompt, run:

conda info --envs

The environments list that displays should not show the removed environment.

Managing packages

Note

There are many options available for the commands described on this page. For details, see Command reference.

Searching for packages

Use the terminal or an Anaconda Prompt for the following steps.

To see if a specific package, such as SciPy, is available for installation:

conda search scipy

To see if a specific package, such as SciPy, is available for installation from Anaconda.org:

conda search --override-channels --channel defaults scipy

To see if a specific package, such as iminuit, exists in a specific channel, such as http://conda.anaconda.org/mutirri, and is available for installation:

conda search --override-channels --channel http://conda.anaconda.org/mutirri iminuit

Installing packages

Use the terminal or an Anaconda Prompt for the following steps.

To install a specific package such as SciPy into an existing environment "myenv":

conda install --name myenv scipy

If you do not specify the environment name, which in this example is done by --name myenv, the package installs into the current environment:

conda install scipy

To install a specific version of a package such as SciPy:

conda install scipy=0.15.0

To install multiple packages at once, such as SciPy and cURL:

conda install scipy curl

Note

It is best to install all packages at once, so that all of the dependencies are installed at the same time.

To install multiple packages at once and specify the version of the package:

conda install scipy=0.15.0 curl=7.26.0

To install a package for a specific Python version:

conda install scipy=0.15.0 curl=7.26.0 -n py34_env

If you want to use a specific Python version, it is best to use an environment with that version. For more information, see Troubleshooting.

Installing packages from Anaconda.org

Packages that are not available using conda install can be obtained from Anaconda.org, a package management service for both public and private package repositories. Anaconda.org is an Anaconda product, just like Anaconda and Miniconda.

To install a package from Anaconda.org:

  1. In a browser, go to http://anaconda.org.

  2. To find the package named bottleneck, type bottleneck in the top-left box named Search Packages.

  3. Find the package that you want and click it to go to the detail page.

    The detail page displays the name of the channel. In this example it is the "pandas" channel.

  4. Now that you know the channel name, use the conda install command to install the package. In your terminal window or an Anaconda Prompt, run:

    conda install -c pandas bottleneck
    

    This command tells conda to install the bottleneck package from the pandas channel on Anaconda.org.

  5. To check that the package is installed, in your terminal window or an Anaconda Prompt, run:

    conda list
    

    A list of packages appears, including bottleneck.

Note

For information on installing packages from multiple channels, see Managing channels.

Installing non-conda packages

If a package is not available from conda or Anaconda.org, you may be able to find and install the package via conda-forge or with another package manager like pip.

Pip packages do not have all the features of conda packages and we recommend first trying to install any package with conda. If the package is unavailable through conda, try finding and installing it with conda-forge.

If you still cannot install the package, you can try installing it with pip. The differences between pip and conda packages cause certain unavoidable limits in compatibility but conda works hard to be as compatible with pip as possible.

Note

Both pip and conda are included in Anaconda and Miniconda, so you do not need to install them separately.

Note

Conda environments replace virtualenv, so there is no need to activate a virtualenv before using pip.

It is possible to have pip installed outside a conda environment or inside a conda environment.

To gain the benefits of conda integration, be sure to install pip inside the currently active conda environment and then install packages with that instance of pip. The command conda list shows packages installed this way, with a label showing that they were installed with pip.

You can install pip in the current conda environment with the commandconda install pip, as discussed in Using pip in an environment.

If there are instances of pip installed both inside and outside the current conda environment, the instance of pip installed inside the current conda environment is used.

To install a non-conda package:

  1. Activate the environment where you want to put the program:

    • On Windows, in your Anaconda Prompt, run activate myenv.

    • On macOS and Linux,in your terminal window, run source activate myenv.

  2. To use pip to install a program such as See, in your terminal window or an Anaconda Prompt, run:

    pip install see
    
  3. To verify the package was installed, in your terminal window or an Anaconda Prompt, run:

    conda list
    

    If the package is not shown, install pip as described in Using pip in an environmentand try these commands again.

Installing commercial packages

Installing a commercial package such as IOPro is the same as installing any other package. In your terminal window or an Anaconda Prompt, run:

conda install --name myenv iopro

This command installs a free trial of one of Anaconda's commercial packages called IOPro, which can speed up your Python processing. Except for academic use, this free trial expires after 30 days.

Viewing a list of installed packages

Use the terminal or an Anaconda Prompt for the following steps.

To list all of the packages in the active environment:

conda list

To list all of the packages in a deactivated environment:

conda list -n myenv

Updating packages

Use conda update command to check to see if a new update is available. If conda tells you an update is available, you can then choose whether or not to install it.

Use the terminal or an Anaconda Prompt for the following steps.

To update a specific package:

conda update biopython

To update Python:

conda update python

To update conda itself:

conda update conda

Note

Conda updates to the highest version in its series, so Python 2.7 updates to the highest available in the 2.x series and 3.6 updates to the highest available in the 3.x series.

To update the Anaconda metapackage:

conda update conda
conda update anaconda

Regardless of what package you are updating, conda compares versions and then reports what is available to install. If no updates are available, conda reports "All requested packages are already installed."

If a newer version of your package is available and you wish to update it, type y to update:

Proceed ([y]/n)? y

Preventing packages from updating (pinning)

Pinning a package specification in an environment prevents packages listed in the pinned file from being updated.

In the environment's conda-meta directory, add a file named pinned that includes a list of the packages that you do not want updated.

EXAMPLE: The file below forces NumPy to stay on the 1.7 series, which is any version that starts with 1.7, and forces SciPy to stay at exactly version 0.14.2:

numpy 1.7.*
scipy ==0.14.2

With this pinned file, conda update numpy keeps NumPy at 1.7.1, and conda install scipy=0.15.0 causes an error.

Use the --no-pin flag to override the update restriction on a package. In the terminal or an Anaconda Prompt, run:

conda update numpy --no-pin

Because the pinned specs are included with each conda install, subsequent conda update commands without --no-pin will revert NumPy back to the 1.7 series.

Removing packages

Use the terminal or an Anaconda Prompt for the following steps.

To remove a package such as SciPy in an environment such as myenv:

conda remove -n myenv scipy

To remove a package such as SciPy in the current environment:

conda remove scipy

To remove multiple packages at once, such as SciPy and cURL:

conda remove scipy curl

To confirm that a package has been removed:

conda list

Managing Python

Conda treats Python the same as any other package, so it is easy to manage and update multiple installations.

Anaconda supports Python 2.7, 3.4, 3.5, and 3.6. The default is Python 2.7 or 3.6, depending on which installer you used:

  • For the installers "Anaconda" and "Miniconda," the default is 2.7.

  • For the installers "Anaconda3" or "Miniconda3," the default is 3.6.

Viewing a list of available Python versions

To list the versions of Python that are available to install, in your terminal window or an Anaconda Prompt, run:

conda search python

This lists all packages whose names contain the text python.

To list only the packages whose full name is exactly python, add the --full-nameoption. In your terminal window or an Anaconda Prompt, run:

conda search --full-name python

Installing a different version of Python

To install a different version of Python without overwriting the current version, create a new environment and install the second Python version into it:

  1. Create the new environment:

    • To create the new environment for Python 3.6, in your terminal window or an Anaconda Prompt, run:

      conda create -n py36 python=3.6 anaconda
      

      Note

      Replace py36 with the name of the environment you want to create. anaconda is the metapackage that includes all of the Python packages comprising the Anaconda distribution. python=3.6 is the package and version you want to install in this new environment. This could be any package, such as numpy=1.7, or multiple packages.

    • To create the new environment for Python 2.7, in your terminal window or an Anaconda Prompt, run:

      conda create -n py27 python=2.7 anaconda
      
  2. Activate the new environment.

  3. Verify that the new environment is your current environment.

  4. To verify that the current environment uses the new Python version, in your terminal window or an Anaconda Prompt, run:

    python --version
    

Using a different version of Python

To switch to an environment that has different version of Python, activate the environment.

Updating or upgrading Python

Use the terminal or an Anaconda Prompt for the following steps.

If you are in an environment with Python version 3.4.2, the following command updates Python to the latest version in the 3.4 branch:

conda update python

The following command upgrades Python to another branch---3.6---by installing that version of Python:

conda install python=3.6
Comments