Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can images be added to Python Package Index documentation?

I have a module repository that features the module code, a README.md file and images used in the README.md file stored at the directory images/ (linked to in README.md using relative links). In order to register and upload the module to PyPI, I have the files setup.py and MANIFEST.in. How should things be such such that the images are included and appear in the PyPI online documentation (as would appear in the hypothetical page https://pypi.python.org/pypi/junkmodule)?

The MANIFEST.in and setup.py that I have currently (and that do not include images in the PyPI online documentation) are as follows:

MANIFEST.in

include LICENSE
include README.md
include images/*
include setup.py
include junkmodule.py

setup.py

#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import setuptools

def main():

    setuptools.setup(
        name             = "junkmodule",
        version          = "0.0.0.1",
        description      = "provides nothing much",
        long_description = Markdown_to_reStructuredText("README.md"),
        url              = "https://github.com/junkuser1/junkmodule",
        author           = "L. Ron. Hubbard",
        author_email     = "[email protected]",
        license          = "GPLv3",
        py_modules       = ["junkmodule"],
        entry_points     = """
            [console_scripts]
            junkmodule = junkmodule:junkmodule
        """
    )

def read(*paths):
    with open(os.path.join(*paths), "r") as filename:
        return filename.read()

def Markdown_to_reStructuredText(filename):
    try:
        import pypandoc
        return pypandoc.convert(filename, "rst")
    except:
        print("pypandoc not found; long description could be corrupted")
        return read(filename)

if __name__ == "__main__":
    main()
like image 353
d3pd Avatar asked Jan 27 '16 13:01

d3pd


People also ask

How do you add a package to Python?

To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.

What is image module in Python?

The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images. PIL. Image.


1 Answers

A possible solution is to host the images on GitHub, and then include the images in the README with their explicit URL.

Take for instance this README: the logo is included with

![](https://raw.githubusercontent.com/mwouts/jupytext/master/docs/logo.png)

And the logo does appear on pip.

Note that you don't even need to host the image in the same GitHub repository - you just need a working URL (an image in another repo, or a gits would work as well).

like image 105
Marc Wouts Avatar answered Sep 22 '22 14:09

Marc Wouts