Create own python package

Create own python package

Before beginning the project work. I request you to register yourself in the official PyPi and kindly remember your username and password which is mandatory to complete this project. Now let start our project.

Create a folder on your desktop, preferably make it the same as your package name. In my case it's pycalcids - python calculator for data science

No alt text provided for this image

Inside the respective folder (pycalcids) create another folder pycalcids, to avoid confusion (I have faced many problems while building the project so try to build the file with the same name). This the folder where we require to develop our python file which handles our entire package.

No alt text provided for this image

Create a python file inside pycalcids to calculate the basic arithmetic values.

def add(a,b):
   c=a+b
   return c

def sub(a, b):
   c=a-b
   return c

def multiply(a, b):
   c=a*b
   return c

def divide(a, b):
   c=a / b
   return c

Save the file as __init__.py. Now your file path looks like the below photo.

No alt text provided for this image

Readme

After uploading the package to the official Python Package website, you will need to provide the use of the package, how it works and how to use this package. So to combine all this work you need a Readme.md file.

Pycalci - Python Calculator for data science
============================


The aim of this package is to create a problem solving module which calculate the basic arithmetic values. Check detailed information about this project via my [GitHub](https://github.com/Ganeshuthiravasagam/pycalci)


Save this file in the root folder pycalcids. Read this article to decorate your Readme files. Click here

License

A license is required for every python packages which is like a doctor requires a medical degree. 13.5% of the packages uploaded in PyPI don’t include any license. The majority of the packages on PyPI, use a “permissive” license, such as the MIT, Apache 2.0.

Copyright (c) 2021 The Python Packaging Authority


Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:


The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.


THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


Save the file as LICENSE.txt in the exact location where Readme file was stored.

Setup file

Now our next step is to build a setup file that pretty much contains every information regarding the module. Let’s take a look at it, you can also edit it as you wish and save it as setup.py

Download the setup file from - GitHub repository. Currently, your folder looks like the below one.

No alt text provided for this image

Command Prompt

Finally, it's time to upload the project to the official PyPi website. Open your command prompt. Install the below libraries

pip install setuptools

pip install twine

pip install wheels


Then provide the respective path where your file has been stored

No alt text provided for this image

Once it's done, type the below command.

 python setup.py bdist_wheel


If everything goes fine you will be getting the following result and new files are added to your folder.

No alt text provided for this image
No alt text provided for this image

Finally, enter the below code

twine upload dist/* 


It will ask for your PyPi username and password (Note: The cursor will remain in the same position while typing the password)

No alt text provided for this image

Surf through the link provided. Hurray, you will be able to see your python package.

No alt text provided for this image

Note: Install and import my package via the below code. "-" is not necessary for your module.

pip install py-calci-ds

import pycalcids

No alt text provided for this image

Thus you have successfully built your module. If anybody is facing issues in building the package ping me on LinkedIn I will help you out. If you found this article useful then kindly share it with your geeky friends.


要查看或添加评论,请登录

社区洞察

其他会员也浏览了