Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add images to a PyPI readme (that works on GitHub)?

In my readme on GitHub I have several images that are present there in my project's source tree which I reference successfully with directives like

.. image:: ./doc/source/_static/figs/moon_probe.png

I would also like to have these images appear when this same readme is generated in PyPi.

How do I (a) ensure that images are present on PyPi for the readme to access and (b) formulate the .. image:: directive to access them?

like image 451
orome Avatar asked Feb 01 '17 15:02

orome


People also ask

How do I add a picture to my readme?

Just add an <img> tag to your README.md with relative src to your repository.

How do I embed an image in GitHub markdown?

Drag and drop the image into the Comment field. The image will start uploading to Github servers. 4) Save the markdown file. And you'll see the image placed inline in the markdown file.


4 Answers

PyPI will not read your package distributions for the image. You have to use the image's external link, for example:

.. image:: https://raw.githubusercontent.com/greyli/flask-share/master/images/demo.png

If you are using Markdown description, use this:

![](https://raw.githubusercontent.com/greyli/flask-share/master/images/demo.png)

Be sure to replace the URL in the above examples with your image URL, here I use the image hosted by GitHub, the real demo is on PyPI.

P.S. To get the image's raw link on GitHub, right-click the image and choose Copy image address.

like image 146
Grey Li Avatar answered Nov 07 '22 06:11

Grey Li


Go to the image address in the Github repository. The path shown will be like this: https://github.com/tensorbored/kds/blob/master/docs/_static/readme_lift.png enter image description here Change the blob term in the image address to raw https://github.com/tensorbored/kds/raw/master/docs/_static/readme_lift.png enter image description here

like image 40
Prateek Sharma Avatar answered Nov 07 '22 05:11

Prateek Sharma


If you have your images on Github, navigate to the image then right click on download button and copy link address:

enter image description here

Then you can add it in your README.md file:

![](https://github.com/your_username/your_repository/raw/master/images/img2.png)

It should be rendered properly both on Github and PyPi.

like image 25
revy Avatar answered Nov 07 '22 07:11

revy


Setting ?raw=True at the end of GitHub image link seems to work.

example:

![Sample image](https://github.com/usename/reponame/blob/master/sample.png?raw=True)

I had found this somewhere on the internet previously, but couldn't find it now. I'll credit the original author when I find it again.

like image 38
Art Avatar answered Nov 07 '22 06:11

Art