In this tutorial, we will learn how to create a Python Package Using Setuptools so that we can share or distribute it among others. I will walk you through all the steps so you may make your own package.
Note: We are going to use visual studio in this tutorial. For more understanding about setting and using Visual Studio, you may refer my tutorial #121 and watch the video to learn the basics of the visual studio and its installation and use.
First, we are going to make a folder, and inside it, we are going to make a license and readme named text files ( we can also use the .md extension to create a markdown file instead of text, which is also a sort of text based file with better editing ). These license files contain the copyright details, and the readme will contain instructions that you want to convey. Along with the text files, we are also going to make a package folder.
Now we will open our visual studio so we can make our work more simple and easier. By writing the command “code .” in our PowerShell, we can open our visual studio with the same directory address. Now we are going to create a setup.py file, and along with it, we will also create an __init__.py file in our package folder.
The package code is present in __init__.py, and setup.py is used for its identification. In simple words, setup.py tells setuptools about our package.
In __init__.py, we will write all the functions we want our package to have. We can uses classes too for this cause. In setup.py, we have to import the setuptools module, and we are going to use it setup function here.
from setuptools import setup
We will provide it with some basic details about our package, such as:
Now we are going to build our package. We are going to open our terminal window or PowerShell in the same directory, and we are going to install the wheel.
pip install wheel
and after that, we are going to make our package using the command
python setup.py bdist_wheel
python setup.py sdist bdist_wheel
Now our package is created, and we can install it using
pip install package_name
And we can also import it in the same way
from setuptools import setup setup(name="packageharry", version="0.3", description="This is code with harry package", long_description = "This is a very very long description", author="Harry", packages=['packageharry'], install_requires=)
class Achha: def __init__(self): print("Constructor ban gaya") def achhafunc(self, number): print("This is a function") return number
No downloadable resources for this video. If you think you need anything, please post it in the QnA!
Any Course related announcements will be posted here