Skip to content

Anaconda

The Anaconda Python distribution is available for Windows, Mac and Linux. You can download and install the version for your operating system from Anaconda. The individual edition is free for students and researchers. To install, follow the instructions provided on the Anaconda documentation site.

Installing Anaconda adds some new commands to your system. On Windows, you will find a new version of the command window which is configured to interact with Anaconda. On Mac and Linux, the commands can be accessed from an ordinary shell prompt.

Virtual environments

Each Python project you work on will probably need a specific set of packages. Rather than just accumulating packages in a central location over time with each new project you start, Python has the concept of a virtual environment.

To run your Python application code, you need the Python executable itself, plus the additional packages that the applications is built with. Usually, there is a system-wide installation of Python which is used by default. Creating a virtual environment for a specific project consists of making a separate copy of the Python files in a different location in the file system. Packages installed in the virtual environment are only available when the environment is activated.

Packages

There is a huge range of Python packages available that have been created for different purposes. Several organisations maintain repositories of packages which can be accessed using a package manager. The default Python package manager is pip, but Anaconda provides a more versatile tool called conda. Some conda commands are used below, but you will need to become familiar with its other uses. The Anaconda documentation site provides some good reference and tutorial material.

You can use conda to create and manage virtual environments and the packages they contain. However, the PyCharm IDE also has some integration features that make it even easier to manage conda environments. This illustrates an important feature of package-based environments: the environment itself is simply a directory containing a collection of files; however, files can be added, updated and removed in different ways. It is up to you which method is most convenient in a particular situation. Here, we will rely mainly on the features in PyCharm.

Check your Anaconda installation

Although it will not usually be necessary to manage your virtual environments this way, the instructions below use the command line to validate your Anaconda installation.

  1. Open a command shell - on Windows, use the special Anaconda command prompt. The first clue that your installation was successful is the form of the command prompt. It should be prefixed with (base). This indicates that you are currently using the base installation - i.e. no virtual environment has been activated.

  2. Use the command below to return the version of conda that is installed. This verifies that the command is available.

    1
    conda -V
    
  3. Create a new virtual environment with the command below. You will be prompted to confirm the operation. Notice that it is possible to specify the version of Python used in the environment. This can be important for compatibility with other packages.

    1
    conda create -n my_test_env python=3.8
    
  4. Activate your new environment with the command below. Notice what effect this has on the format of the command prompt.

    1
    conda activate my_new_env
    
  5. Check the packages installed in the environment with the command

    1
    conda list
    
  6. Add the Flask package to the environment with the command below. You will be prompted to confirm the installation of the new package and its dependencies.

    1
    conda install flask
    
  7. The current virtual environment can be deactivated with the command

    1
    conda deactivate
    
  8. Remove the test virtual environment with the command

    1
    conda env remove -n my_test_env