导航

 

 本文将演示将python项目打包为模块并上传至pip私服,然后将其从私服下载并使用,从而实现模块化编程的过程。

 这里使用本地搭建的Nexus作为pip仓库。使用Nexus搭建pip私服

1.环境准备

 

pip install --upgrade setuptools
pip install --upgrade wheel
pip install --upgrade twin
#设置镜像源
pip config set global.index-url http://127.0.0.1:8081/repository/pypi_group_test/simple

 

2. 示例项目目录如下:

 说明:每个包下面都必须有一个__init__.py文件(可以为空)

setup.cfg


[metadata]
name = totems_pycommon
version = 1.0.0
long_description = file: README.rst, CHANGELOG.rst, LICENSE.rst
include_package_data = True


[options]
python_requires = >=3.6
packages = find:
package_dir =
=.
# 依赖
install_requires=
kafka==1.2.0
requests


[options.packages.find]
where = .
#include = *
exclude = *.test

[options.package_data]
* = *.ini
 

pyproject.toml

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

2.在setup.cfg所在目录执行打包命令

python -m build

打包成功后目录下会出来dist目录,包含如下文件:

 3.使用twine 将打好的包上传到远程仓库,这里选择上传到本地搭建的Nsxus私服。

twine upload --repository-url http://127.0.0.1:8081/repository/hosted_test/ dist/*

其中hosted_test是Nexus上的本地仓库

查看上传的包:

4.安装包

pip install totems_pycommon

 

 

 

 

 

5.测试使用

 

参考资料:



 

posted on 2021-10-08 17:50  一棵二叉树  阅读(676)  评论(0编辑  收藏  举报