零、先祭出官网连接
一、创建文件的目录结构
/string2date
/string2date
__init__.py
string2date.py
setup.py
LICENSE
README.md
__init__.py
初始化的数据,之后pip install
调包的时候会先加载这里面的数据,所以里面还需要加上
from . import string2date
string2date.py
写的方法
setup.py
from setuptools import setup
setup(name='string2date',
version='0.0.1',
description='string to date',
url='https://github.com/BigDataFounder/string2date',
author='hurpe',
author_email='hurpe.ma@gmail.com',
license='MIT',
packages=['string2date'])
- name
- 就是包名
- version
- 包的版本号
- packages
- 可引入的包的名字,也可以使用
setuptools.find_packages()
去自动导入,我这里就一个包,所以直接写了
- 可引入的包的名字,也可以使用
README.md
自定义的一项,可以简单描述一下包是做什么的
LICENSE
许可证,详细信息可以去官网查看,如果用的是MIT
,可以直接复制下面的。
Copyright (c) 2018 The Python Packaging Authority
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
二、生成档案
如果上述工作都做完了,那么恭喜你可以开始准备上传包了,之后就可以用pip install
下载工具了。
setuptools 和wheel
首先需要保证你有最新版的setuptools
和wheel
python -m pip install --user --upgrade setuptools wheel
Tip:如果出现问题了可以查看官网的解决方案:https://packaging.python.org/tutorials/installing-packages/
进入到和setup.py
同级目录下
python setup.py sdist bdist_wheel
这时会生成两个文件
dist/
string2date-0.0.1-py2-none-any.whl
string2date-0.0.1.tar.gz
三、上传档案到Pypi
利用twine
将包上传上去
首先先安装twine
python -m pip install --user --upgrade twine
注册一个Pypi的账号
之后会用到帐号密码
网站传送门:https://pypi.org/
Tip:
- 不用翻墙
- 有个邮箱验证,需要登录邮箱验证一下
上传
twine upload dist/*
- 默认直接上传到了pypi上,如果想指定上传的位置,也可以指定,如下是上传到测试的
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
注意:这地方我遇到了个坑,可能因为我这个电脑python装了好几个版本,还有anaconda,所以我在下载twine
的时候不在我配置环境变量的路径里,上传的命令一直不能执行,找了半天又加了一个twine
的环境变量才能用
#### 上传成功的命令行
G:\pycode\hurpe\string2date>twine upload dist/string2date-0.0.1*
Enter your username: hurpe
Enter your password:
Uploading distributions to https://upload.pypi.org/legacy/
Uploading string2date-0.0.3-py2-none-any.whl
100%|█████████████████████████████████████| 5.28k/5.28k [00:05<00:00, 1.02kB/s]
Uploading string2date-0.0.3.tar.gz
100%|█████████████████████████████████████| 3.85k/3.85k [00:01<00:00, 2.89kB/s]
四、登录Pypi查看
五、检验
这时候就可以,下载包,然后运行里面方法了
pip install string2date
G:\pycode\hurpe\string2date>python
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import string2date
>>>
六、更新版本
- 更新版本也很简单,只需要修改
setup.py
下的version
- 然后重新生成档案,上传
python setup.py sdist bdist_wheel
twine upload dist/string2date-0.0.2*
七、更新本地moudle版本
pip install --upgrade string2date
或者是先卸载,再安装
# 卸载string2date
pip uninstall string2date
# 安装string2date
pip install string2date