python模块打包方法

http://www.jb51.net/article/92789.htm

一 首先将模块的目录结构整理如下:

VASPy/
├── LICENSE
├── MANIFEST
├── MANIFEST.in
├── README.rst
├── requirements.txt
├── scripts
│  ├── change_incar_parameters.py
│  ├── create_inputs.py
│  └── ...
├── setup.cfg
├── setup.py
├── tests
│  ├── incar_test.py
│  ├── __init__.py
│  ├── oszicar_test.py
│  ├── outcar_test.py
│  ├── testdata
│  │  ├── CONTCAR
│  │  ├── DOS_SUM
│  │  ├── ELFCAR
│  │  └── ...
│  └── ...
└── vaspy
  ├── __init__.py
  ├── iter.py
  ├── matstudio.py
  └── ...

注意上面的MANIFEST.in,requirements.txt, setup.py vaspy以及里面的__init__.py这些是必须 

注意vaspy和里面的vaspy的一致。

tests是子包,scripys也是 子包,matstudio.py可以是模块入口文件

MANIFEST.in

此文件在打包的时候告诉setuptools还需要额外打包那些文件,例如我VASPy中的单元测试的测试数据文件我就使用这个文件将其包含进来。当然README,LICENSE这些也可以通过它来一起打包进来。
下面是我自己的MANIFEST.in的内容:

include README.rst
include requirements.txt
include LICENSE
recursive-include scripts *
recursive-include tests *

也就是把一些 必须 的文件还有子包引入进去

vaspy/

此文件夹就是vaspy源代码所在的包。个人理解是一个和模块名同名的文件夹

setup()的参数

name

versions = "vaspy"

是整个项目的名字,打包后会使用此名字和版本号。

 

 

description

是一个简短的对项目的描述,一般一句话就好,会显示在pypi上名字下端。

long_description

是一个长的描述,相当于对项目的一个简洁,如果此字符串是rst格式的,PyPI会自动渲染成HTML显示。这里可以直接读取README.rst中的内容。

url

包的连接,通常为GitHub上的链接或者readthedocs的链接。

packages

需要包含的子包列表,setuptools提供了find_packages()帮助我们在根路径下寻找包,这个函数distutil是没有的。

setup_requires

这个参数定义了VASPy安装和顺利运行所需要的其他依赖项(最基本的),使用pip安装的时候会对这些依赖项进行安装。
关于这个参数与requirements.txt的区别可以参考:install_requires vs Requirements files

classifier

这个参数提供了一系列的分类,在PyPI上会将其放入不同的目录中讲项目进行归类。

#!/usr/bin/env python

from setuptools import setup, find_packages


maintainer = 'Shao-Zheng-Jiang'
maintainer_email = 'shaozhengjiang@gmail.com'
author = maintainer
author_email = maintainer_email
description = "A pure Python library designed to make it easy and quick to manipulate VASP files"

long_description = """
=====
test1
=====
.. image:: https://travis-ci.org/PytLab/test1.svg?branch=master
    :target: https://travis-ci.org/PytLab/test1
    :alt: Build Status
.. image:: https://landscape.io/github/PytLab/test1/master/landscape.svg?style=flat
    :target: https://landscape.io/github/PytLab/test1/master
    :alt: Code Health
.. image:: https://codecov.io/gh/PytLab/test1/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/PytLab/test1
.. image:: https://img.shields.io/badge/python-3.5, 2.7-green.svg
    :target: https://www.python.org/downloads/release/python-351/
    :alt: platform
.. image:: https://img.shields.io/badge/pypi-v0.8.8-blue.svg
    :target: https://pypi.python.org/pypi/test1/
    :alt: versions
Introduction
------------
test1 is a pure Python library designed to make it easy and quick to manipulate VASP files.
You can use test1 to manipulate VASP files in command lins or write your own python scripts to process VASP files and visualize VASP data.
In `/scripts <https://github.com/PytLab/test1/tree/master/scripts>`_ , there are some scripts written by me for daily use.
Installation
------------
1. Via pip(recommend)::
    pip install test1
2. Via easy_install::
    easy_install test1
3. From source::
    python setup.py install
If you want to use **mayavi** to visualize VASP data, it is recommened to install `Canopy environment <https://store.enthought.com/downloads/#default>`_ on your device instead of installing it manually.
After installing canopy, you can set corresponding aliases, for example:
.. code-block:: shell
    alias canopy='/Users/<yourname>/Library/Enthought/Canopy/edm/envs/User/bin/python'
    alias canopy-pip='/Users/zjshao/Library/Enthought/Canopy/edm/envs/User/bin/pip'
    alias canopy-ipython='/Users/<yourname>/Library/Enthought/Canopy/edm/envs/User/bin/ipython'
    alias canopy-jupyter='/Users/<yourname>/Library/Enthought/Canopy/edm/envs/User/bin/jupyter'
Then you can install test1 to canopy::
    canopy-pip install test1
"""

install_requires = [
    'configparser',
    'selenium',
]


# Get long description.
#with open("README.rst") as f:
#    lines = f.readlines()
#
#long_description = ""
#for line in lines:
#    if "Installation" in line:
#        break
#    else:
#        long_description += line

name = 'test1'
packages = [
    'test1',
]
platforms = ['linux']

# classifiers = [
#     'Development Status :: 3 - Alpha',
#     'Topic :: Text Processing',
#     'License :: OSI Approved :: MIT License',
#     'Programming Language :: Python :: 2',
#     'Programming Language :: Python :: 2.7',
#     'Programming Language :: Python :: 3',
#     'Programming Language :: Python :: 3.5',
# ]

setup(author=author,
      author_email=author_email,
      description=description,
      license=license,
      long_description=long_description,
      install_requires=install_requires,
      maintainer=maintainer,
      name=name,
      packages=find_packages(),
      platforms=platforms,
#      test_suite="tests",
     )

上面 是我自己修改后的,有一些不是必须 

 模块打包好后,安装方法 

python setup.py install

原文地址:https://www.cnblogs.com/xqnq2007/p/8177053.html