Python module Python module distributiondistribution
Modules in PythonModules in Python
Modules are everywhereModules are everywhere
IntroductionIntroduction In order to share your newly created module, you need In order to share your newly created module, you need
to prepare a distribution. This is the Python name given to prepare a distribution. This is the Python name given to the collection of files that together allow you to build, to the collection of files that together allow you to build, package, and distribute your module.package, and distribute your module.
The The Python Package Index (or Python Package Index (or PyPI for short) PyPI for short) provides a centralized repository for third-party Python provides a centralized repository for third-party Python modules on the Internet. When your module modules on the Internet. When your module is readyis ready, , you’ll use PyPI to publish your module and make your you’ll use PyPI to publish your module and make your code available for use by others. code available for use by others.
Once a distribution exists, you can install your module Once a distribution exists, you can install your module into your local copy of Python, as well as upload your into your local copy of Python, as well as upload your module to PyPI to share with the world. module to PyPI to share with the world.
Step1: Creating a folder for your module.Step1: Creating a folder for your module. With the folder created, copy your ‘.py’ module file into the folder. Let’s With the folder created, copy your ‘.py’ module file into the folder. Let’s
call the folder “modist”call the folder “modist”
Step 2: Create a file called “setup.py” in your new folder.Step 2: Create a file called “setup.py” in your new folder. This file contains metadata about your distribution. Edit this file by adding This file contains metadata about your distribution. Edit this file by adding
the following code:the following code:
Folder structureFolder structure
Build a distribution fileBuild a distribution file
Step 3: Open a terminalStep 3: Open a terminal window within your ‘mymoddist’ folder and type a single window within your ‘mymoddist’ folder and type a single
command: command:
C:\python27\mymoddist\python setup.py sdist.C:\python27\mymoddist\python setup.py sdist.
OrOr
lab1@lab1-ThinkCentre-M58p:~/modist$python setup.py :~/modist$python setup.py sdistsdist
A collection of status messages appears on screen, A collection of status messages appears on screen, confirming the creation of your distribution.confirming the creation of your distribution.
Output screen Output screen
Install your distribution into Install your distribution into your local copy of Python.your local copy of Python.
Staying in the terminal, type this command: sudo python3 setup.py install.
lab1@lab1-ThinkCentre-M58p:~/modist$ python setup.py install.
Another bunch of status messages appear on screen, confirming the installation of your distribution
Register with the PyPI website
Begin by surfing over to the PyPI website at http://pypi.python.org/ and
Upload your code to PyPI
With your registration details entered and saved, you are now ready to upload your distribution to PyPI. Another command line does the trick: