[PYTHON] PyPI registration steps for those who want to make a PyPI debut

Introduction

I recently made my PyPI debut. So I will write a registration procedure for those who are thinking of making a PyPI debut for the same purpose.

What is PyPI? is it delicious?

It seems to be an abbreviation for Python Package Index. A service for managing Python packages, anyone can register a package. The packages registered here can be installed with `` `pip install```. By the way, it seems to read Pipey Eye.

Package preparation

First, prepare the package to be registered. This time, I will create a package called "pypipkg" as an example. The file structure looks like this. Prepare the information necessary for registering PyPI such as setup.py directly under the pypipkg directory, and also place the pypipkg source directory.

pypipkg $ tree
├── MANIFEST.in
├── README.rst
├── pypipkg
│   ├── __init__.py
│   ├── dependency.py
│   ├── scripts
│   │   ├── __init__.py
│   │   └── command.py
│   └── verify.py
├── requirements.txt
└── setup.py

The configuration prepared for the first time is like the above. Later, the directories needed for pip will be added during the registration process.

pypipkg $ tree
├── MANIFEST.in
├── README.rst
├── dist
│   ├── pypipkg-1.0.0.tar.gz
│   ├── pypipkg-1.0.1.tar.gz
│   ├── pypipkg-1.0.2.tar.gz
│   ├── pypipkg-1.0.3.tar.gz
│   └── pypipkg-1.0.4.tar.gz
├── pypipkg
├── pypipkg.egg-info
│   ├── PKG-INFO
│   ├── SOURCES.txt
│   ├── dependency_links.txt
│   ├── entry_points.txt
│   ├── requires.txt
│   └── top_level.txt
├── requirements.txt
└── setup.py

Create setup.py

Setup.py is important for PyPi registration. Based on the information in this setup.py, it can be recognized as a package and registered. Probably the most troublesome to create setup.py with PyPI registration.

#!/usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
import os

from setuptools import setup, find_packages

try:
    with open('README.rst') as f:
        readme = f.read()
except IOError:
    readme = ''

def _requires_from_file(filename):
    return open(filename).read().splitlines()

# version
here = os.path.dirname(os.path.abspath(__file__))
version = next((line.split('=')[1].strip().replace("'", '')
                for line in open(os.path.join(here,
                                              'pypipkg',
                                              '__init__.py'))
                if line.startswith('__version__ = ')),
               '0.0.dev0')

setup(
    name="pypipkg",
    version=version,
    url='https://github.com/user/pypipkg',
    author='kinpira',
    author_email='[email protected]',
    maintainer='kinpira',
    maintainer_email='[email protected]',
    description='Package Dependency: Validates package requirements',
    long_description=readme,
    packages=find_packages(),
    install_requires=_requires_from_file('requirements.txt'),
    license="MIT",
    classifiers=[
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
        'License :: OSI Approved :: MIT License',
    ],
    entry_points="""
      # -*- Entry points: -*-
      [console_scripts]
      pkgdep = pypipkg.scripts.command:main
    """,
)

At first glance, it feels like you're doing a lot of difficult things, but the important thing is in setup (). It is OK if you write each setting item here. The items specified in the setup.py example above are as follows.

  install_requires=[
        "hoge",
  ],

【wiki: MIT】

In summary, the MIT License is the following license.

  1. Anyone can use this software for free and unlimited. However, the copyright notice and this license notice must appear on all copies or important parts of the software.
  2. The author or copyright holder is not responsible for the software.

This information is also explained in the python documentation.

Created by MANIFEST.in

After creating setup.py, this time we are using the method of specifying requirements.txt, so create a "MANIFEST.in" file. MANIFEST.in can be included in the package by specifying it when you want the package to intentionally include files that are not included in the target python directory.

By the way, if requirements.txt etc. are specified like this time, if MANIFEST.in does not exist, an error will occur because requirements.txt does not exist at the time of installation.

Package testing

When you're ready to package, start by packaging and testing locally. If you want to test locally, you can package it with the `` `python setup.py develop``` command and install it in site-packages.

$ cd ~/pypipkg
$ python setup.py develop

This will allow you to call it with import in your python project. The command created by entry_points in setup.py can also be used locally, so you can check if it works as a package without any problem.

Register with TestPyPI

By registering with TestPyPI before registering with the production PyPI, you can perform a series of operations such as checking the display of the PyPI page and installing, just like the production.

First of all, you need to register an account as in the actual production, so create an account.

↓ The TestPyPI page is written as TESTING SITE like this. スクリーンショット 2016-06-07 11.59.27.png

pypirc

If you want to use TestPyPi, you need to create .pypirc in the HOME directory as shown below. (Reference)


$ vim ~/.pypirc

[distutils]
index-servers =
  pypi
  pypitest

[pypi]
repository=https://pypi.python.org/pypi
username=your_username
password=your_password

[pypitest]
repository=https://testpypi.python.org/pypi
username=your_username
password=your_password

TestPyPI register Once pypirc is created, go directly under the package where setup.py is located and use the register command to register the package information in TestPyPI.

python setup.py register -r https://testpypi.python.org/pypi

TestPyPI search After registering the information with register, it seems that you can check it with the search command. (In my case, it didn't work out for some reason)

pip search --index https://testpypi.python.org/pypi pypipkg

TestPyPI upload The register command only registers the package information, but the gzip (source code) of the package itself has not been uploaded yet, so registration is completed only after uploading the substance with the upload command.

python setup.py sdist upload -r https://testpypi.python.org/pypi

TestPyPI install After uploading, you can install with ``` pip install` ``.

pip install --index-url https://testpypi.python.org/simple/ pypipkg

I think you have successfully installed it. Once you've confirmed this, all you have to do is publish it to the production PyPI.

Register for production PyPI

Now let's publish it to the production PyPI.

You need to register an account here as well, so create an account.

https://pypi.python.org/

Once you have an account, we will register. The procedure is the same as for TestPyPI.

PyPI register First, register with the register command.

python setup.py register

PyPI upload Next, use the upload command to upload the entity.

python setup.py sdist upload

PyPI site confirmation

Yes! Now that registration is complete, let's check it on the PyPI site. Like this スクリーンショット 2016-06-08 12.59.10.png

It's published perfectly, so you can now install it with `pip install`!

Summary

At first I thought that setup.py was troublesome, but once I wrote it, the registration work after that was very easy. Besides, the environment for testing is properly prepared, so I was able to make my PyPI debut with less resistance than I expected.

Recommended Posts

PyPI registration steps for those who want to make a PyPI debut
Anxible points for those who want to introduce Ansible
For those who want to write Python with vim
For those who want to start machine learning with TensorFlow2
Reference reference for those who want to code in Rhinoceros / Grasshopper
Loose articles for those who want to start natural language processing
Python techniques for those who want to get rid of beginners
A memo for those who want quick socket communication with netcat
A modern environment building procedure for those who want to get started with Python right away
[Short sentence] easygui for those who want to use a simple GUI with Python very easily
I analyzed Airbnb data for those who want to stay in Amsterdam
I want to make matplotlib a dark theme
I want to make a game with Python
Join Azure Using Go ~ For those who want to start and know Azure with Go ~
For those who want to learn Excel VBA and get started with Python
5 Reasons Processing is Useful for Those Who Want to Get Started with Python
The first step of machine learning ~ For those who want to implement with python ~
PostgreSQL-For those who want to INSERT at high speed
I want to find a popular package on PyPi
[Python] I want to make a nested list a tuple
Environment construction for those who want to study python easily with VS Code (for Mac)
When you want to plt.save in a for statement
ABC's A problem analysis for the past 15 times to send to those who are new to Python
For those who want to display images side by side as soon as possible with Python's matplotlib
[For those who want to use TPU] I tried using the Tensorflow Object Detection API 2
How to manage a README for both github and PyPI
I want to make a blog editor with django admin
Experiment to make a self-catering PDF for Kindle with Python
I want to make a click macro with pyautogui (desire)
How to make a Python package (written for an intern)
I want to make a click macro with pyautogui (outlook)
I want to make input () a nice complement in python
[Discord.py] A solution for those who cannot successfully introduce disperser
I want to create a Dockerfile for the time being.
[AWS] A story that may be helpful for those who are new to Lambda-Python and DynamoDB
For those of you who don't know how to set a password with Jupyter on Docker
[2020 version for beginners] Recommended study method for those who want to become an AI engineer by themselves
"The Cathedral and the Bazaar" that only those who work in a solid company want to read
Python environment construction 2016 for those who aim to be data scientists
[For beginners] How to register a library created in Python in PyPI
Spigot (Paper) Introduction to how to make a plug-in for 2020 # 01 (Environment construction)
How to make a unit test Part.1 Design pattern for introduction
[Introduction] I want to make a Mastodon Bot with Python! 【Beginners】
I want to make a parameter list from CloudFormation code (yaml)
I tried to make a strange quote for Jojo with LSTM
A memo for those who use Python in Visual Studio (me)
Beginners want to make something like a Rubik's cube with UE4 and make it a library for reinforcement learning # 4
[Hi Py (Part 1)] I want to make something for the time being, so first set a goal.
Beginners want to make something like a Rubik's cube with UE4 and make it a library for reinforcement learning # 5
Beginners want to make something like a Rubik's cube with UE4 and make it a library for reinforcement learning # 6
How to make a Japanese-English translation
Make a Tweet box for Pepper
Steps to create a Django project
How to make a slack bot
How to make a crawler --Advanced
How to make a recursive function
How to make a deadman's switch
[Blender] How to make a Blender plugin
How to make a crawler --Basic
How to make a model for object detection using YOLO in 3 hours
I tried to make a face diagnosis AI for a female professional golfer ①