Setting up a dependency file in Python

ยท

2 min read

Setting up a dependency file in Python

My fellow developers in the javascript developer will be conversant with the package.json file which is usually located in the project root and contains the various metadata relevant it the project. This file contains much information such as the name of the project, author, email, GitHub URL, project URL, project dependencies, run scripts, and some other information. In python, this file is called the setup.py file and in this tutorial we would be learning how to set up this file.

First, we would have to have python downloaded and installed. With the new latest version of python, the python package manager pip should be installed with it. To check and ensure that python and pip are installed, run this code on the terminal, which will show the versions of python and pip respectively. For Python

py --version
 // Expected result: "Python 3.10.4"

For pip

py -m pip --version
//Expected result: pip 22.0.4

From the system terminal, we have to install setuptool package which will handle the installation of dependencies and project setup. To install: py -m pip install setuptools

Having done the necessary installations, let's write the setup file. In the root directory of the project create a setup.py file.

from setuptools import setup

setup(

name='' , #name of the project

author='', #author of the project

# Your email address:
author_email='',

#version
version: '',

#license
license: '',

#description of the project
description: '',

# Link to your github repository or website: 
url='/',

# Download Link from where the project can be downloaded from/live-link:
download_url='',

# List project dependencies: 
install_requires=['python packages', ' ', .... ],
)

The install_requires is an array of all the dependencies needed and used in the project.

The setup.file is ready, to run the file: py -m setup.py install

This will automatically install all the packages listed in the install_requires array and your project is fully set up with relative ease.

What a nice and helper file that is right...start writing and utilizing the setup.py file and happy coding...๐Ÿ˜๐Ÿ˜

Thanks๐Ÿ˜Ž

ย