Audvik Labs

Python Packages

Introduction

A Python package usually consists of several modules. Physically, a package is a folder containing modules and maybe other folders that themselves may contain more folders and modules. Conceptually, it’s a namespace. This simply means that a package’s modules are bound together by a package name, by which they may be referenced.

A package is a directory of Python modules that contains an additional

__ init __ .py file, which distinguishes a package from a directory that is supposed to contain multiple Python scripts. Packages can be nested to multiple depths if each corresponding directory contains its own _ init __ .py file.

Installing a Python package

Installing a python package is pretty simple with the help of the pip tool.

The pip command is a tool for installing any Python packages which are mostly found in the Python Package Index. Your system needs to have the pip installed inorder to install any python package.

Installation of pip:

sudo apt-get install python-pip

After pip is installed in the system, search for the python package to install in their library and install using their pip install command:

pip install

Now we know how to install a python package, let’s learn how to create a python package.

Creating a Python Package

There are prerequisites to install before we proceed. These are:

Setuptools: It is a package development process library designed to create and distribute Python packages.

pip install setuptools

Wheel: The Wheel package provides a bdist_wheel command for the setuptools. It creates a .whl file which is directly installable through the pip install command.

pip install wheel

Twine: The Twine package provides a secure, authenticated, and verified connection between your system and PyPi over HTTPS.

pip install twine

Setup the project for Python package

Create a setup file setup . py in your package. This file must contain all your package metadata information.

Compiling the package

Execute the following command to compile the python package:

python setup.py bdist_wheel

After compiling the package, it will create following structure:

build: build package information.

dist: Contains your .whl file. A WHL file is a package saved in the Wheel format, which is the standard built-package format used for Python distributions. You can directly install a .whl file using pip install some_package.whl on your system

project . egg . info: An egg package contains compiled bytecode, package information, dependency links, and captures the info used by the setup . py test command when running tests.

Python’s packaging ecosystem contains multitudes. It can be intimidating for new Python developers to try to crack into, especially given the rapid evolution of Python packaging. Writing a helloworld . py file and running it on your computer is simple, but getting it to run on someone else’s computer (and doing this the “right” way) involves a tangle of terms, tools, and techniques.

Python is an ocean of libraries that serve various purposes and as a Python developer, you must have sound knowledge of the best ones.

Some Common Python libraries

  1. TensorFlow

This library was developed by Google in collaboration with Brain Team. TensorFlow is a part of almost every Google application for machine learning.

TensorFlow works like a computational library for writing new algorithms that involve a large number of tensor operations, since neural networks can be easily expressed as computational graphs they can be implemented using TensorFlow as a series of operations on Tensors. Plus, tensors are N-dimensional matrices which represent your data.

  1. Scikit-Learn

It is a Python library  associated with NumPy and SciPy. It is considered as one of the best libraries for working with complex data.

There are a lot of changes being made in this library. One modification is the cross-validation feature, providing the ability to use more than one metric. Lots of training methods like logistics regression and nearest neighbors have received some little improvements.

  1. Numpy

Numpy is considered as one of the most popular machine learning library in Python.

TensorFlow and other libraries uses Numpy internally for performing multiple operations on Tensors. Array interface is the best and the most important feature of Numpy.

  1. Keras

Keras is considered as one of the coolest machine learning libraries in Python. It provides an easier mechanism to express neural networks. Keras also provides some of the best utilities for compiling models, processing data-sets, visualization of graphs, and much more.

In the backend, Keras uses either Theano or TensorFlow internally. Some of the most popular neural networks like CNTK can also be used. Keras is comparatively slow when we compare it with other machine learning libraries. Because it creates a computational graph by using back-end infrastructure and then makes use of it to perform operations. All the models in Keras are portable.

  1. Pandas

Pandas is a machine learning library in Python that provides data structures of high-level and a wide variety of tools for analysis. One of the great feature of this library is the ability to translate complex operations with data using one or two commands. Pandas have so many inbuilt methods for grouping, combining data, and filtering, as well as time-series functionality.

Leave a comment

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