python distutils basic package and release

distutils package to achieve release of the package

Import Math 


DEF showMsg (A):
     return A * A * A 


A = 10
 Print ( ' % D cube is D% ' % (A, showMsg (A)))
package.py

1. Set up setup.py in the same directory

# Encoding = UTF-8 
from distutils.core Import setup, Extension 

# packaged software must be setup script file name 
# packing function 
setup ( 
    name = ' Package Penalty for ' ,   # install the package name 
    Version = ' 1.0 ' ,   # packaged versions of installed software No. 
    Description = " achieved cubic logarithmic operation " , 
    LONG_DESCRIPTION = " to achieve the cubic operand " , 
    author = ' feiquan123 ' , 
    author_email =' [email protected] ' ,
     # the Maintainer to = "None", the other defenders # provide information related to the package name 
    # maintainer_email = "None", Mailbox # defenders 
    url = "" ,   # packets associated site's home page access address 
    DOWNLOAD_URL = "" ,   # downloading the installation package (zip, exe) the URL 
    Keywords = " Math " , 
    the py_modules = [ ' package ' ],   # set packaging module, the plurality may 
    # for C, C ++, Java ranking when packaged with tripartite expansion module, you specify the extension, source extension, and any compile / link requirements (including directories, libraries, etc.) 
    ext_modules = [the extension ( ' Data ' ,['data.c'])],
)

Note: If your setup.py contains Chinese characters, the first line of code must be written

How to extend and embedding Python interpreter:  https://docs.python.org/zh-cn/3/extending/index.html

2. Write the installation configuration file setup.cfg

[Sdist] 
dist dir = source

dist-dir: Specifies the release of the source code path, the default dist

How to write setup.cfg:

Common commands: (see '--help-commands' for more)

  setup.py build      will build the package underneath 'build/'
  setup.py install    will install the package

Global options:
  --verbose (-v)  run verbosely (default)
  --quiet (-q)    run quietly (turns verbosity off)
  --dry-run (-n)  don't actually do anything
  --help (-h)     show detailed help message
  --no-user-cfg   ignore pydistutils.cfg in your home directory

Options for 'sdist' command:
  --template (-t)        name of manifest template file [default: MANIFEST.in]
  --manifest (-m)        name of manifest file [default: MANIFEST]
  --use-defaults         include the default file set in the manifest
                         [default; disable with --no-defaults]
  --no-defaults          don't include the default file set
  --prune                specifically exclude files/directories that should
                         not be distributed (build tree, RCS/CVS dirs, etc.)
                         [default; disable with --no-prune]
  --no-prune             don't automatically exclude anything
  --manifest-only (-o)   just regenerate the manifest and then stop (implies
                         --force-manifest)
  --force-manifest (-f)  forcibly regenerate the manifest and carry on as
                         usual. Deprecated: now the manifest is always
                         regenerated.
  --formats              formats for source distribution (comma-separated
                         list)
  --keep-temp (-k)       keep the distribution tree around after creating
                         archive file(s)
  --dist-dir (-d)        directory to put the source distribution archive(s)
                         in [default: dist]
  --medata-check         Ensure that all required elements of meta-data are
                         supplied. Warn if any missing. [default]
  --owner (-u)           Owner name used when creating a tar file [default:
                         current user]
  --group (-g)           Group name used when creating a tar file [default:
                         current group]
  --help-formats         list available distribution formats

usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help
setup.py --help sdist

 

3. publishing software (archive)

linux : python setup.py  sdist
windows : setup.py sdist
Specify publishing format, while generating two compressed: python setup.py sdist --formats = gztar, zip
windows exe : python setup.py bdist_wininst

4. Install the source package, you can then import the

Cd to extract the directory after extracting 
the installation command python setup.py install 
saved installation logs or when installed: python setup.py install --record log

5. After installing deleted

Python setup.py install log 1. Installation - Record log
 2. Windows: for / I F.% In (log) do del % I 
     Linux: CAT log | xagrs RM -rf

Where: log file contents is the installation directory:

E:\...\Lib\site-packages\package.py
E:\...\Lib\site-packages\__pycache__\package.cpython-37.pyc
E:\...\Lib\site-packages\package-1.0-py3.7.egg-info

 

Guess you like

Origin www.cnblogs.com/feiquan/p/11566659.html