How to install a library in Python

Python library installation can be done in four ways listed below. Ideally only one of the ways should have worked! But it doesn’t! and sometimes even all these four steps also don’t work!! Simply because, python library install is a mess!!. Try installing keras or tensorflow library, you will understand what I am saying 🙂

If everything goes well, the pip command itself will successfully install your required library and you won’t have to use the other three methods.

  • Using pip
  • Using conda
  • Using a wheel file
  • manual zip file download

A library has to be installed only once using any one of the above-listed steps. Once done, then you just import the library in every session.

What happens when a library is installed?

A folder is downloaded from either the python repository(pip) or the anaconda repository(conda) and kept into the Lib/site-packages folder present inside the installation folder of your system’s python.

This is something you can perform manually as well by downloading the zip file of the library from the pypi.org but, in this case, you will have to download all the dependent packages as well, which could be cumbersome.

pip install

pip is the first command you must try in order to install a new package in python. pip will download the required package as well as its dependencies.

Installing a library using pip command
Installing a python library using pip command


conda install

If pip command fails then you can use conda install command. The difference between pip and conda is the repository from where it downloads the package. pip uses the pypi.org and conda uses the anaconda repository.

Installing a library using conda
Installing a library using conda


Using wheel file

A wheel file is a packaged version of a library with the required dependencies metadata and the binaries.

  1. Download the wheel file from the internet and put it in the Anaconda3/Scripts folder
  2. Fire below command from anaconda command prompt as shown
  3. pip install opencv_python-2.4.13.2-cp27-cp27m-win_amd64.whl

Installing a library using wheel file
Installing a library using the wheel file


Manual zip file download

Download the zip file from the internet and put it in the Anaconda3/Lib/site-packages/ folder

Installing the library by manually downloading the zip file
Installing the library by manually downloading the zip file

Author Details
Lead Data Scientist
Farukh is an innovator in solving industry problems using Artificial intelligence. His expertise is backed with 10 years of industry experience. Being a senior data scientist he is responsible for designing the AI/ML solution to provide maximum gains for the clients. As a thought leader, his focus is on solving the key business problems of the CPG Industry. He has worked across different domains like Telecom, Insurance, and Logistics. He has worked with global tech leaders including Infosys, IBM, and Persistent systems. His passion to teach inspired him to create this website!

1 thought on “How to install a library in Python”

  1. Pingback: My Site

Leave a Reply!

Your email address will not be published. Required fields are marked *