A few years back when I typed
pip install opencv-python, a few seconds passed and something magical happened- I was able to use OpenCV; no need to build it from source, no compiler needed, it was definitely breathtaking. I could install any package I wanted and not worry about building it source/ installing or configuring the system variable.
Note: This article was originally posted on Medium.
Over the years, I continued using pip and every time, it didn't fail to fascinate me. It really made me wonder how simple a piece of technology can be. Being a Windows user, every time I installed something new, I had to configure the system path. So this definitely made my life simpler.
Files in the same module can always be imported by all files in the directory. But what if you want to make your module available throughout your system?
You add a setup.py to your module (with relevant configuration of course).
But what if you want python package available to everyone across the globe?
You publish your package on PyPI. (so everyone can pip install your-package-name)
Enough talk, let's write some code. Let's write a simple function and package it.
# hello.py def heythere(): print("hey there")
# setup.py #!/usr/bin/env python # -*- coding: utf-8 -*- from setuptools import setup, find_packages setup( author="Chinmay Shah", firstname.lastname@example.org', classifiers=[ 'License :: OSI Approved :: MIT License', 'Programming Language :: Python :: 3.7', ], description="Says hello", license="MIT license", include_package_data=True, name='hello', version='0.1.0', zip_safe=False, )
Setup.py is what
pip looks for in a given directory. It uses something called setuptools which enables packaging. It contains the name of your package, a brief description of your package, along with author information. And don't fail to mention which python version it's made for. All of this metadata is important.
But what does it mean when I say it installs it?
First, it creates a wheel (
.whl) file; which is an accepted file for package distribution.
In the installation process, it uses this wheel file and installs it in site-package directory(Anaconda uses this).
In-case of downloading it from the internet, a local cache is often created in
But what is
pip is a package installer for Python used to install packages (mainly) from PyPI(Python Package Index). Launched in 2008 as an upgrade to
easyinstall, even though both are built on top of setuptools. 
PyPI is a vast package index where anyone can submit their package, and anyone across the globe can do pip install your-package-name .
Look out for the next post, where I'll be covering on how to write package as well as publishing it on PyPI.
 Setuptools - https://setuptools.readthedocs.io/en/latest/