[PYTHON] I tried to publish my own module so that I can pip install it

wrap up

Self-made module

pip install my_awesome_module

To publish it so that it can be published, it is OK to publish it on GitHub together with setup.py

GitHub page: https://github.com/kyohashi/model_selection

What is pip install doing in the first place?

I'm looking for a module on PyPI (Python Package Index). For example, if you access PyPI.org and search for numpy, ↓ https://pypi.org/

Certainly there is numpy. ↓ https://pypi.org/search/?q=numpy

When registering a module on PyPI, you will need setup.py, which represents the meta information of the module, along with the source code of the module. To summarize the above,

  1. pip install hogehoge
  2. Go to PyPI and search for name = hogehoge
  3. Recognize and install setup.py associated with hogehoge as a loading module

You can understand that you are following the procedure.

How to publish your own module

It turns out that you can pip install by registering with PyPI, but you can actually publish it on GitHub as well. The point is that you only need to tell me the source code and the location of setup.py, so after registering on GitHub

pip install git+(URL)

Anyone can install it. This time I tried publishing on GitHub instead of PyPI.

The files registered on GitHub and setup.py are as follows.

file organization


.
├── README.md
├── requirements.txt
├── setup.py
└── src
    └── model_selection
        ├── __init__.py
        ├── bayes_clustering.py
        └── utils
            ├── __init__.py
            └── check_datashape.py
    

setup.py


from glob import glob
from os.path import basename
from os.path import splitext

from setuptools import setup
from setuptools import find_packages


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


setup(
    name="model_selection",
    version="0.1.0",
    description="statistical model selection with Bayesian IC like WAIC",
    author="kyohashi",
    url="https://github.com/kyohashi/model_selection.git",
    packages=find_packages("src"),
    package_dir={"": "src"},
    py_modules=[splitext(basename(path))[0] for path in glob('src/*.py')],
    include_package_data=True,
    zip_safe=False,
    install_requires=_requires_from_file('requirements.txt')
)

If you look at setup.py, you can see that it recognizes the python files under the src folder as modules. If you register the above, it will be fine

pip install git+https://github.com/kyohashi/model_selection.git

Is possible.

Contents of the published self-made module

The module created this time aims to help determine the number of clusters. Specifically, as shown in the figure below, the optimal number of clusters is estimated by modeling and calculating WAIC with GMM for all candidate cluster numbers. PyMC3 is used for MCMC sampling.

Untitled Diagram.png

There is also an implementation example for Toy Data, so please refer to it as well. Usecase: https://kyohashi.github.io/model_selection/gmm_usecase.html

Recommended Posts

I tried to publish my own module so that I can pip install it
I tried to expand the database so that it can be used with PES analysis software
[I tried using Pythonista3] Importing my own module
I tried to deepen my understanding by making my own discriminator that can classify binary using logistic regression.
I tried to scrape YouTube, but I can use the API, so don't do it.
I uploaded a module to pypl that deletes Japanese stop words, so share it
I made my own Django Middleware so that I can access request information from anywhere
I tried to make OneHotEncoder, which is often used for data analysis, so that it can reach the itch.
I stumbled when I tried to install Basemap, so a memorandum
I made my own OSS because I wanted to contribute to it
[Python] I made my own library that can be imported dynamically
I tried Python! ] Can I post to Kaggle on my iPad Pro?
PyPi debut I tried to pip install a library to check Japanese holidays
I was addicted to pip install mysqlclient
I tried how to improve the accuracy of my own Neural Network
I got an SSL related error with pip install, so I solved it
I want to pip install with PythonAnywhere
I tried to make a calculator with Tkinter so I will write it
I tried to install Docker on Windows 10 Home but it didn't work
Github Interesting Repository ① ~ I found a graphic repository that looks interesting, so I tried it ~
I tried my best to return to Lasso
[Ansible] I want to call my own function from the template module (macro)
I tried to make my own source code compatible with Chainer v2 alpha
I tried to create a class that can easily serialize Json in Python
I tried using the Python library "pykakasi" that can convert kanji to romaji.
I failed to install django with pip, so a reminder of the solution
[I'm an IT beginner] I tried my best to implement Linux on Windows
I didn't understand the Resize of TensorFlow so I tried to summarize it visually.
I tried my best to make an optimization function, but it didn't work.
[Personal memo] pip install fails, so solve it
Steps to install your own library with pip
[Rails] v1.0 came out on google-cloud-vision of gem, so I tried to support it
I tried to make a memo app that can be pomodoro, but a reflection record
A Python beginner made a chat bot, so I tried to summarize how to make it.
I want to add my own structure to the structure created by Python's C extension module!
It's Cat Day, so I tried to make something that translates into cat-like words.
I realized that it is nonsense to use the module without thinking because it is convenient.
I got an error when pip install pandas on Mac, so I dealt with it
I wanted to operate google spread sheet with AWS lambda, so I tried it [Part 2]
I tried learning my own dataset using Chainer Trainer
AWS Lambda now supports Python so I tried it
I tried to install scrapy on Anaconda and couldn't
I got an error when pip install tweepy on macOS Sierra, so I dealt with it
I made a tool that makes it a little easier to create and install a public key.
When I tried to install PIL and matplotlib in a virtualenv environment, I was addicted to it.
Install Mecab and CaboCha on ubuntu16.04LTS so that it can be used from python3 series
There was a doppelganger, so I tried to distinguish it with artificial intelligence (laughs) (Part 1)
How to install pip
I tried to debug.
I tried to paste
Until you can install your own Python library with pip
I published my own Python baseball library to Packaging & PyPI
Ubuntu blew up when I tried to change my username
PyTorch's book was difficult to understand, so I supplemented it
[Flask] I tried to summarize the "docker-compose configuration" that can be created quickly for web applications
I tried to make a site that makes it easy to see the update information of Azure
I made my own 3-layer forward propagation neural network and tried to understand the calculation deeply.
[Graduation from article scattering] I tried to develop a service that can list articles by purpose
When I tried to use pip with python, I was told that XML_SetHashSalt could not be found.
I tried to make my own high school girl BOT with Rinna style with LINE BOT (Python & Heroku)
A story that didn't work when I tried to log in with the Python requests module