Register as a package on PyPI

I registered the package on PyPI for the first time, so I will summarize what I did.

enable setup.py

The directory structure is as simple as it gets.

.
├── LICENSE.txt
├── README.md
├── nbupload
│   ├── FileUploaderView.js
│   ├── FileUploaderWidget.py
│   └── __init__.py
└── setup.py

Since it manages git, .gitignore for Python is also included.

Write a minimal setup.py. packages = ['nbupload'] is a way to write a directory name as a package. For details, refer to Documentation.

from setuptools import setup

setup(
    name = "nbupload",
    version = "0.0.1",
    packages=['nbupload'],
)

with this,

python setup.py develop

If you type, it will be installed for develop and you can import it normally. As an entity, there was a file called nbupload.egg-link in the python site-packages directory, in which the path to the package directory was written.

Uninstall

python setup.py develop -u

It's fine.

Register with pypi

setup.py is lonely above, so add more.

If you don't have a pypi account, get one. There is also a testpypi for the package registration test, so register an account there as well. Please note that the password to be registered must be placed in the home directory in plain text (although it can be deleted immediately).

I feel that the password must be 16 characters or more and there are no uppercase or lowercase letters. Google's OpenID can't be used because Google no longer supports new registrations.

Create .pypirc in your home directory. (If you only register on pypi, you don't have to put this (?), But if you have testpypi, you have to put this)

I referred to here.

[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}}

Register with testpypi.

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

Now you have an item on your pypi, and you can also find it on pip search --index https://testpypi.python.org/pypi nb upload.

However, as it is, there is no actual package anywhere yet, so I have to upload gzip. You can also write download_url in setup.py and specify the gzip of the github tag, but by default pip install ignores URLs other than pypi (you can pass it with --allow-external). Good to upload to pypi itself. The next command does that.

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

You can now install it with pip install --index-url https://testpypi.python.org/simple/ nbupload.

If you can do so far, all you have to do is register for the production pypi.

python setup.py register
python setup.py sdist upload

It ends with.

Bonus: Include non-python files in the package

This time I had to include JS in the package and distribute it, so I had to write this in setup.py.

    package_data = {
        'nbupload': ['FileUploaderView.js'],
    },

If you don't do this, by default packaging with python setup.py sdist upload will not include any non-python files.

Recommended Posts

Register as a package on PyPI
How to register a package on PyPI (as of September 2017)
How to register on pypi
I want to find a popular package on PyPi
Build a Pypi cache server on QNAP
[Python] Register your own library on PyPI
Semi-automatically generate a description of the package to be registered on PyPI
Like as soon as a reply comes on Twitter
A memo created in a package and registered in PyPI
A Python beginner was addicted to registering his own package on PyPI, February 2017 version
Visualize Go's internal package relationships on a commit-by-commit basis
How to use Fujifilm X-T3 as a webcam on Ubuntu 20.04
A memorandum to register the library written in Hy in PyPI
Get the package version to register with PyPI from Git
[Java] Spigot plugin development --Register the command as a vanilla command
Create a local pypi repository
A comment on Boruta algorithm
Use Remotte as a user
Create a classroom on Jupyterhub
Run a Java app that resides on AWS EC2 as a daemon
PyPI package for super easy use of Cotoha on Google colab
[For beginners] How to register a library created in Python in PyPI
I tried to register a station on the IoT platform "Rimotte"
How to deploy a web application on Alibaba Cloud as a freelancer