您当前的位置:首页 > IT编程 > python
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:如何将自己的python代码发布在pip install给别人使用你知道吗

51自学网 2021-10-30 22:16:59
  python
这篇教程如何将自己的python代码发布在pip install给别人使用你知道吗写得很实用,希望能帮到您。

1.编写模块结构

1.1 git创建空文件

阿里云git上创建一个空项目yuesf08, 项目属性为public, 并下拉到本地,如下图所示git/yuesf08。

1.2 编写包功能函数

yuesf08文件下创建包yuesfpug, 第一个init函数必须存在,第二个是用户编写的函数。

# init.py# -*- coding:utf-8 -*-from . import add_num# add.num.py# -*- coding:utf-8 -*-def add_num(a,b):    return a+b

 

1.3 包必备函数

1、README.md文件是在git上生成的说明项目的文件

2、setup.py文件内容

from distutils.core import  setupimport setuptoolspackages = ['yuesfpug']# 唯一的包名setup(name='yuesfpug',	version='1.0',	author='yuesf',    packages=packages,     package_dir={'requests': 'requests'},)

3、liciense.txt文件内容

Copyright © 2021 yuesf Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

2. 生成模块

2.1 提前安装需要的库

pip install twinepip install wheel

2.2 生成上图的1-3文件

cmd一定要进入路径D:/yuesf/shangfei/git/yuesf08

# 1. 编译python setup.py build# 2. 生成发布压缩包:python setup.py sdist# 3. 生成网络发布包wheel文件:python setup.py bdist_wheel

 

3. 安装本地包

cmd一定要进入路径D:/yuesf/shangfei/git/yuesf08/dist

pip install yuesfpug-1.0-py3-none-any.whl

 

4. 本地测试

通过测试我们发现,add_num.py实际上可以看作一个模块,里面的函数也是add_num,所以调用是add_num.add_num(a,b)

5. 上传到pypi

cmd一定要进入路径D:/yuesf/shangfei/git/yuesf08/dist

pypi官网注册,上传代码时填写pypi账号、密码。

twine upload dist/*

 

6. 安装上传的包

先删除本地安装的包,再安装上传的包,这个时候的路径是C盘。

总结

本篇文章就到这里了,希望能够给你带来帮助,也希望您能够多多关注51zixue.net的更多内容!


python爬虫之Appium爬取手机App数据及模拟用户手势
python闭包和装饰器你了解吗
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。