Python Open source package submitted to the PyPI community

Source: Internet
Author: User

Why submit to PyPI? Since the submission is successful, you will want to use your own module, as long as the PIP install a bit.

So how to submit? See this tutorial

First of all to determine what your package name, such as my bag called XLUTILS3, since it is OK, then create the name of the folder, and then put the source into the folder, and then check the folder inside the file of each import library is written to the path, Like Xlutils.copy, you have to change to xlutils3.copy.

Then is to create a file under the folder __init__.py , the content can be all empty, organized into a package of the file structure is probably like this:

xlutils3/    |    +--__init__.py    |    +--myscripts1.py    |    +--mysscripts2.py    |    +--mymorescripts.py    |

XLUTILS3 is the name of the package, my***.py the following various files are the original code modules.

If this package does not upload to PyPI, pure local use has no problem at all.

So you have to check some of the internal method functions, you can import and then call methods to check

If you want to pack on the PyPI, then you need to add the material on top of it. First, you need to adjust the directory structure of the following file, change the above to look like this:

xlutils3/    |    +--xlutils3/    .       +--__init__.py    .       +--myscripts1.py    .       +--mysscripts2.py    .       +--mymorescripts.py    .       |    |

is to place the original XLUTILS3 folder under another Xlutils3 folder, and then create some files in the topmost folder:

XLUTILS3    |    +--COPYING.txt    |    +--README.txt    |    +--setup.py    |    +--xlutils3    .       +--__init__.py    .       +--myscripts1.py    .       +--mysscripts2.py    .       +--mymorescripts.py    .       |    +--docs/    |

In addition to the Docs directory, none of the other files can be less.

    1. COPYING.txt is the authorization file, which is your authorization on this package, such as: MIT license, then you put in the MIT license full text can, of course, you can not do this file.
    2. README.txt, try to put something in here, we might use it in the back. It is important to note that the return of Windows is not the same as Linux, so it is recommended to use Windows. Alternatively, you can use README.rst this type of file instead
    3. setup.py, the core file, the contents of which we will speak immediately.
    4. docs/, this folder you put your documents, but it is difficult to write the document, so this folder basically does not exist-for their own laziness shameful.
    5. If the package is a file, then you can also completely do not have to consider building a layer of directories, directly into the directory of the Readme file is available, although I do not recommend this operation.

setup.py sample file as follows, not much to say, please delete the Chinese note before submitting

Import codecsimport osimport sys try:    from setuptools Import setupexcept:     from distutils.core Import Setup "" "The packaged setup must be introduced," "" " def Read (fname):    " ""      defines a read method to read the long description under the directory      we generally read the contents of the Readme file as a long description, This will show up on the page of your package in PyPI,     You can also use this method to write your own content manually, &NBSP;&NBSP;&NBSP;&NBSP;PYPI support. RST formatted files. Temporarily does not support. MD formatted files, <br>.rst file PyPI automatically turns it into HTML as it appears on your package's information page.      "" "    return Codecs.open (Os.path.join (Os.path.dirname (__file__), fname). Read ()    name = "Somefunctions" "" "name, usually put your package name can be" ""  packages = ["Somefunctions",] "" " Contains the package that can be multiple, which is a list "" " description =" This is a test pack for packing Python liberaries tutorial. "" "" Description of the package "" " long_description = Read (" Readme.rst ")" "" See Read Method description "" " keywords =" Test python package "" " For the current package of some keywords, convenient pypi classification. "" " author =" Mitchellchu "" "" Who is the author of this package, who wrote the name ofI am Mitchellchu, nature is written here is Mitchellchu "" " author_email =" [email protected] "" "The author's e-mail Address" " url =" http:/ blog.useasp.net/"" "You this package project address, if there is, give a bar, without you directly fill in PyPI you this package address is also available" "" " version =" 1.0.1 "" "" "" "" "" "" "" "" " This version control mode you need to "" "" ""  license = "mit" "" "licensing method, I like the way MIT, you can switch to other ways" ""  setup (    name = Name,    version = Version,    description = DESCRIPTION,     long_description = Long_description,    classifiers = [          ' License:: OSI Approved:: MIT License ',         ' Programming Language:: Python ',         ' intended audience:: Developers ',          ' Operating System:: OS independent ',     ],     keywords = Keywords,    author = Author,    authoR_email = Author_email,    url = Url,    license = LICENSE,     packages = Packages,    include_package_data=true,    zip_ Safe=true,)  ## fill in the above variables into a setup ().

It is worth noting that classifiers can not write, otherwise it will cause upload failure

In general, Distutils will only contain all of the. py files in your package folder that are defined inside of the. py file, all of which are included in the parameter, and README.txt setup.py packages py_modules Other files need to be added separately. Need to add, you can add a file in the root directory, MANIFEST.in will include the file into, specific rules please refer to the Official document format. As we need to add here COPYING.txt can MANIFEST.in add the following line in: Include COPYING.txt

After writing, in order to check, you can enter a python setup.py check in the directory where the CD to the setup.py file is located in the command line.

It's always you. setup.py file didn't write right.

You can package without an abnormal output: Python setup.py sdist

Can be uploaded after packaging, but it is recommended to take the package to other non-packaged places to install and run it again

You can do it directly: go to PyPI to register an account, and then enter the Python setup.py register sdist on the command line upload

Running Registerwe need to know who is, so please choose Either:1. Use your existing login, 2. Register as a new use R, 3. The server generate a new password for you (and email it to you), or 4. Quityour selection [Default 1]: 1

General will be error, so I suggest in the setup.py of the same directory on the account file, the account file name is. PYPIRC, the contents are as follows:

[pypi]repository = Https://pypi.python.org/pypi[server-login]username:slqtpassword: "Your password"

Remember the documents written by Windows, and at the beginning there will be annoying bom! There are two ways to solve this problem:

1. Delete BOM with EditPlus Hex Editor

2. Create a good file in Linux and drag it to Windows, then wrap it up.

Then re-execute the python setup.py sdist and subsequent operations, upload OK after you can go to the page to look at, and then uninstall the local, and then pip install test under

Here is the address of the package I published HTTPS://PYPI.PYTHON.ORG/PYPI/XLUTILS3

Python Open source package submitted to the PyPI community

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.