Python 官方文档:入门教程 => 点击学习
目录1.编写模块结构1.1 git创建空文件1.2 编写包功能函数1.3 包必备函数1、README.md文件是在git上生成的说明项目的文件2、setup.py文件内容3、lici
在 阿里云git上创建一个空项目yuesf08, 项目属性为public, 并下拉到本地,如下图所示git/yuesf08。
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
from distutils.core import setup
import setuptools
packages = ['yuesfpug']# 唯一的包名
setup(name='yuesfpug',
version='1.0',
author='yuesf',
packages=packages,
package_dir={'requests': 'requests'},)
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.
pip install twine
pip install wheel
cmd一定要进入路径D:\yuesf\shangfei\git\yuesf08
# 1. 编译
python setup.py build
# 2. 生成发布压缩包:
Python setup.py sdist
# 3. 生成网络发布包wheel文件:
python setup.py bdist_wheel
cmd一定要进入路径D:\yuesf\shangfei\git\yuesf08\dist
pip install yuesfpug-1.0-py3-none-any.whl
通过测试我们发现,add_num.py实际上可以看作一个模块,里面的函数也是add_num,所以调用是add_num.add_num(a,b)
cmd一定要进入路径D:\yuesf\shangfei\git\yuesf08\dist
在pypi官网注册,上传代码时填写pypi账号、密码。
twine upload dist/*
先删除本地安装的包,再安装上传的包,这个时候的路径是C盘。
本篇文章就到这里了,希望能够给你带来帮助,也希望您能够多多关注编程网的更多内容!
--结束END--
本文标题: 如何将自己的python代码发布在pip install给别人使用你知道吗
本文链接: https://www.lsjlt.com/news/134022.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0