chengjun / iching

A python package of I Ching 《易经》蓍草卦的Python版本
https://pypi.python.org/pypi/iching/
MIT License
109 stars 39 forks source link

How to release a Python package to PyPI #7

Open chengjun opened 11 months ago

chengjun commented 11 months ago

Releasing a Python package to PyPI (Python Package Index) involves several steps. Here's a step-by-step guide to help you publish your Python package:

1. Create Your Python Package:

First, make sure your Python package is properly structured. It should contain the necessary files like setup.py (for package metadata), your Python code, and any other required files.

2. Prepare Your Package:


Quick installation::

  pip install iching

Quick Start::

  from iching import iching

  iching.predict(19850927, 20180119)

See the details: https://github.com/chengjun/iching/blob/master/DESCRIPTION.rst

3. Create an Account on PyPI:

If you haven't already, create an account on PyPI.

4. Install Required Tools:

Make sure you have the necessary tools installed:

   pip install setuptools wheel twine

5. Build Your Package:

Navigate to your package directory and run the following commands to build your package:

   python setup.py sdist bdist_wheel

For example:

(base) MacBook-Pro-4:iching datalab$ python setup.py sdist bdist_wheel

This will create distribution packages in the dist directory.

6. Upload Your Package:

Use twine to upload your package to PyPI. Run the following command:

   twine upload dist/*

(base) MacBook-Pro-4:iching datalab$ twine upload --verbose --repository-url https://upload.pypi.org/legacy/ --username chengjun --password <your_password> dist/*

Please replace with your PyPI password.

This command will upload all files in the dist directory to PyPI.

chengjun commented 11 months ago
INFO     Response from https://upload.pypi.org/legacy/:                                                                              
         400 The description failed to render in the default format of reStructuredText. See                                         
         https://pypi.org/help/#description-content-type for more information.                                                       
INFO     <html>                                                                                                                      
          <head>                                                                                                                     
           <title>400 The description failed to render in the default format of reStructuredText. See                                
         https://pypi.org/help/#description-content-type for more information.</title>                                               
          </head>                                                                                                                    
          <body>                                                                                                                     
           <h1>400 The description failed to render in the default format of reStructuredText. See                                   
         https://pypi.org/help/#description-content-type for more information.</h1>                                                  
           The server could not comply with the request since it is either malformed or otherwise incorrect.<br/><br/>               
         The description failed to render in the default format of reStructuredText. See                                             
         https://pypi.org/help/#description-content-type for more information.                                                       

          </body>                                                                                                                    
         </html>                                                                                                                     
ERROR    HTTPError: 400 Bad Request from https://upload.pypi.org/legacy/                                                             
         The description failed to render in the default format of reStructuredText. See                                             
         https://pypi.org/help/#description-content-type for more information.                                                       
(base) MacBook-Pro-4:iching datalab$ 
chengjun commented 10 months ago

DESCRIPTION.rst 很难设置,会导致上传到pypi失败。