python anacondapython anaconda
Spread the love

Introduction

Anaconda is a free and open-source distribution of Python and R programming for data science and machine learning applications. It has more than 1500 Python/R data science packages.

It comes with tools like Spyder, Visual Studio Code, R, Powershell, JupyterLab, and Jupyter notebook.

Anaconda makes package management and deployment much simpler. It helps you create a virtual environment that makes it easy to deploy any project.

Benefits of Using Python Anaconda

Why should you use Anaconda for your project? Well, it does have the following benefits:

  • It is free and open-source
  • It has more than 1500 Python/R data science packages
  • Anaconda simplifies package management and deployment
  • It has tools to easily collect data from sources using machine learning and AI
  • It creates an environment that is easily manageable for deploying any project
  • Anaconda is the industry standard for developing, testing and training on a single machine
  • It has good community support- you can ask your questions there.
    What you get
  • Manage libraries, dependencies, and environments with conda
  • Build and train ML and deep learning models with scikit-learn, TensorFlow and Theano
  • Use Dask, NumPy, Pandas and Numba to analyze data scalably and fast
  • Perform visualization with Matplotlib, Bokeh etc

Understanding Virtual Environment

Python is a versatile language and can be used for anything. For example Data analysis, Machine learning, Artificial Intelligence or Web development, etc. Each of these tasks requires different packages and versions of Python.

To use these packages and versions efficiently, we use a virtual environment.

It allows each project to have its own dependencies and we can easily switch between applications regardless of what dependencies and requirements they have.

Conda is one such package manager and environment manager included in anaconda.

General Syntax

  >> conda create -n envname python=x.x anaconda

Replace envname with the name you want to give to your virtual environment and x.x with the Python version you want to use.

Installing Packages Using Anaconda

     >> conda install numpy

# list packages that can be updated
    >> conda search –outdated

# update all packages prompted(by asking the user yes/no)
   >> conda update –all

# update all packages unprompted
   >> conda update –all -y

Installing GPU Packages

   >> conda install py-xgboost-gpu

Dealing with Package not found

   >> anaconda search -t conda xgboost

Now install one of the installable packages as follows :

>> conda install -c mndrake xgboost


Example : Setting up Jupyter

   >> conda install -c anaconda jupyter

Running Jupyter Notebook

You can move into your programming environment and run Jupyter Notebook:

   >> jupyter notebook

Adding packages to Python Anaconda

Over 250 packages are automatically installed with Anaconda and more than 75,00 open source packages can be aditionally installed using conda install command.

Using conda-forge

To install packages using conda-forge command, run the following syntax in anaconda command prompt:

 >> conda install -c conda-forge PACKAGENAME

Example:

  >> conda install -c conda-forge numpy

Using pip command

To install packages using the pip command, run the following syntax in the anaconda command prompt:

  >> pip install PACKAGENAME

Example:

  >> pip install pandas

Creating, Listing and Switching Environments

  >> conda create –name myenv

  >> conda env list

Activating Environment

  >> conda activate tf-gpu


Jupyter Crashing Multiple Times

If you’re going to install with conda, run conda clean -tipsy to clean up conda caches before you start.

  >> conda clean -tipsy


conda remove

Remove a list of packages from a specified conda environment.

This command will also remove any package that depends on any of the specified packages as well—unless a replacement can be found without that dependency. If you wish to skip this dependency checking and remove just the requested packages, add the ‘–force’ option. Note however that this may result in a broken environment, so use this with caution.

conda uninstall

To remove all packages from a specific environment tf-gpu from the base environment :-

 >> conda uninstall -n tf-gpu –all

Adding Conda Environment to Jupyter Notebook

Now comes the step to set this conda environment on your jupyter notebook, to do so please install ipykernel.

  >> conda install -c anaconda ipykernel

After installing this, just type,

  >> python -m ipykernel install –user –name=firstEnv

Using the above command, will now have this conda environment in my Jupyter notebook.

Conclusion

This tutorial provides in-depth and hands-on introduction to anaconda, its commands, and major use cases. You can use it any time to refer to many of the typical working scenarios in day to day development of data science projects. Good Luck !

By Hassan Amin

Dr. Syed Hassan Amin has done Ph.D. in Computer Science from Imperial College London, United Kingdom and MS in Computer System Engineering from GIKI, Pakistan. During PhD, he has worked on Image Processing, Computer Vision, and Machine Learning. He has done research and development in many areas including Urdu and local language Optical Character Recognition, Retail Analysis, Affiliate Marketing, Fraud Prediction, 3D reconstruction of face images from 2D images, and Retinal Image analysis in addition to other areas.