Python

Anaconda Python Tutorial

In this tutorial, we are going to discuss what Anaconda is, how to install Anaconda, how to use Spyder, and how to start programming in Python using Anaconda. We will mention all the details with a proper explanation to get started. Let’s first begin with what an actual Anaconda is.

What Is Anaconda?

Data science and machine learning employ the Python and R distribution known as Anaconda. You don’t need to install many of the libraries and tools separately because they are pre-installed on it. These libraries and tools include NumPy, Spyder, Pandas, Matplotlib, Scikit-learn, Jupyter, and many others.

In addition to being a distribution of Python and R, Anaconda also includes several other tools and features that are useful for data science and machine learning. An example of a tool that is included in Anaconda is the Anaconda Navigator, a graphical user interface that makes it simple to launch the applications and manage the packages. It also includes the tools for working with Jupyter notebooks which are widely used in data science for writing and running code, as well as for creating documents that mix with text, code, and visualizations.

What Is Conda?

In addition to these packages, Anaconda also includes tools to manage and deploy the data science projects. For example, it includes Conda which is a package and environment manager that allows you to create separate environments for different projects and easily install and update the packages. It also includes tools to work with Jupyter notebooks which are widely used in data science for writing and running code, as well as for creating documents that mix with text, code, and visualizations.

If you need to utilize multiple versions of packages or Python itself, Anaconda’s ability to establish distinct environments for various projects might be helpful. When working on a new project, you can move to a different environment after setting up an environment with a particular version of Python and the packages you require. This can assist you in avoiding disagreements and maintaining the package organization.

Prerequisite:

The following are some prerequisites to understand the rest of this article:

  • Python programming language’s most recent version
  • An environment of integrated development (IDE)
  • Having access to user-friendly package management so you can use the Python-based technologies which are made by others, including Pandas and TensorFlow

It is quite useful that Anaconda offers all three of these tools in a single, straightforward download. And because free things are always welcome, we’ll mention that Anaconda is free for individual usage.

You’re equipped to go there because installing Anaconda by default installs the most recent version of Python. Many of the essential Python packages for data science and machine learning, including NumPy, SciPy, and Matplotlib, are also installed automatically by Anaconda. This implies that after installing Anaconda, all that is left to do is choose an IDE.

How to Install Anaconda

Anaconda is available for free download at https://www.anaconda.com/. It can be installed on Windows, Linux, and macOS. You have two options to manage the packages and environments with Anaconda:

Use the Anaconda Navigator: A variety of tools and features for data science and scientific computing are available through the graphical user interface known as the Anaconda Navigator which is part of the Anaconda distribution. You can use it to launch the applications and manage the packages including installing and updating the packages, and creating and managing the environments.

Use the Command Line: You can also use the command line (terminal or command prompt) to manage the packages and environments with Anaconda. The Conda package manager, which you may use to install, update, and delete the packages as well as create and manage the environments, is a component of the Anaconda distribution. To use Conda from the command line, you need to enter the Conda commands such as conda install, conda update, and conda create.

You may choose between the Python 2 and Python 3 versions based on your needs.

Anaconda & Spyder Installation Process for Windows

  1. First, click on the following link. It opens the download page.

Free Download

  1. To download Anaconda, follow these steps:

Go to the Anaconda website (https://www.anaconda.com/)

Click on the “Download” button.

Check that your system is compatible with Anaconda.

The download begins automatically.

  1. To start the installation process for Anaconda, double-click on the installer file. This launches the installer and begins the installation process.
  2. Click on Next.
  3. To continue with the Anaconda installation, you need to read the license agreement and then click on the “I Agree” button to agree on the terms of the agreement. You can then carry on with the installation process after that.
  4. During the Anaconda installation process, you will be requested to select the installation type. These are your two choices:

“Just Me” (recommended): This option installs Anaconda for the current user only. It does not require any special privileges and is the recommended option for most users.

“All Users”: This option installs Anaconda for all users on the computer. It requires Windows Administrator privileges and is only necessary if you want to make Anaconda available to all users on the computer.

To select the installation type, pick the appropriate option. After that, click “Next” to proceed.

  1. This is the location on your computer where Anaconda and its associated files and tools will be installed.
  2. During the installation process of Anaconda, you will be asked to add Anaconda to your PATH environment variable. The PATH environment variable should NOT include Anaconda since this may cause conflicts with other programs. Decide if Anaconda should be set as your default Python. Unless you want a different version of Python or Anaconda and not the default version, leave this option chosen.
  3. You will get the “Thanks for installing Anaconda” dialogue box following a successful installation.

What Is Spyder?

An integrated development environment (IDE) called Spyder is available for free with Anaconda. The Scientific Python Development Environment is what it stands for. It has tools for editing, interactive testing, debugging, and introspection.

Get Started with Python Programming Language with Anaconda

  1. Type “Spyder” into the Windows search box and hit Enter.
  2. When Spyder IDE is opened, three areas are visible:
    1. Editor
    2. Console
    3. Variable/help/file/plot space

How to Start Programming in Python Using Anaconda

Let’s try some code in the Editor. Refer to the following given examples:

Example 1:

In this example, we execute a simple program to show you how things work. We display a simple “Welcome” message.  The print statement to display this message is mentioned in the following:

print (“Welcome”)

After this, click on run to execute the program.

The output can be seen in the console.

Example 2:

Here, we will help you understand how to make a triangle in Python. In the attached code, you can see that we created three variables in which we store the first, second, and third angles of a triangle. After that, another variable named “res_traingle” is created in which we take the sum of the previous three values. Following that, the if and else statements are used where we check if the sum is equal to 180 or not. If it equals to 180, the “ It is triangle” message is displayed on the screen. Otherwise, the “ Not a triangle” message is displayed.

first =int(input("Please enter the first angle of triangle:"))

second = int(input("Please enter the second angle of triangle:"))

third = int(input("Please enter the third angle of traingle:"))

res_traingle = first+second+third

if res_traingle==180:

  print("Triangle")

else:

  print("Not a triangle")

For your conveyance, we executed the programs two times with different inputs. The results of the first execution are shown in the following:

How to Update the Package Management by Launching the Anaconda Prompt

Here is the command to update the package:

conda update conda

How to Create a New Environment and Mention the Python Version

The instructions to build a new environment are listed in the following. Furthermore, you have the choice of specifying the version.

conda create -n myenv python=3.7

Now, you can easily activate the environment:

conda activate myenv

To deactivate the environment successfully, use the following given command:

conda deactivate

Install additional packages into the environment using conda, install, or pip install. For example:

conda install numpy scipy pandas

You can also use the Anaconda Navigator to manage your environment and packages. To launch it, open the Anaconda Prompt and enter the following command:

anaconda-navigator

To list the environments that you created, use the following command:

conda env list

To easily delete an environment, the following command can be used:

conda env remove -n myenv

To update a package, the command is as follows:

conda update package_name

To update all packages which are contained in an environment, execute the following given command:

conda update –all

Conclusion

We showed how to obtain and set up Anaconda for Python. We demonstrated that the process is straightforward to follow. Anaconda is a powerful and useful tool for data science, and it offers a range of products and resources that can be extremely helpful for your work. We also highlighted the convenience and effectiveness of Anaconda’s virtual environment which allows you to easily install and manage the software packages. Overall, Anaconda is a valuable asset for anyone who is working in data science.

About the author

Kalsoom Bibi

Hello, I am a freelance writer and usually write for Linux and other technology related content