IT Panda Blog

Life is fantastic


  • Home

  • Tags

  • Categories

  • Archives

Python 项目打包,上传至Artifactory,并下载安装

Posted on 2020-05-04 In python

Python Packing

Python Project结构

1
2
3
4
5
6
7
python_project/
package/
__init__.py
xx.py
setup.py
LICENSE
README.md

上面是一个Python Project最基本的结构,包含:

  • package folder:
  • __init__.py 和 你真正的Python module文件 xx.py
  • setup.py
  • LICENSE license 文件: 具体想要什么样license,可以去这里找 https://choosealicense.com/
  • README.md 不仅是README,甚至可以放一些配置文件,这些配置文件可以被诸如 setup.py 所引用

__init__.py

将自己的module expose出去的配置文件;比如我自定义了了一个module rex_test,我需要将其expose出去

1
2
#__init__.py
from . import rex_test

setup.py

关于如何package的一个configuration文件,例如

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import setuptools

setuptools.setup(
name='rexg',
version='1.0.0',
author='Rex',
author_email='rex@g.com',
description='Rex test Python packaging',
url='https://rexg.github.io/',
install_requires=[
'mlflow==1.0.0',
],
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
)

使用到的命令

打包

1
2
pip install --upgrade setuptools wheel
python setup.py sdist bdist_wheel

这是项目的 /dist folder下就会生成 *.tar.gz 的打包文件;

上传至Artifactory

1
2
pip install --upgrade twine
python -m twine upload -u <username> -p <passwd> -r <repo> --repository-url https://artifactory.xxx dist/*

引用

1
sudo pip install -i https://artifactory.xxx/simple rexg
python
OpenFaaS 101 - 4:Design & Architecture
Go问题列表
  • Table of Contents
  • Overview
Rex

Rex

25 posts
26 categories
49 tags
Links
  • GitHub
  1. 1. Python Project结构
    1. 1.1. __init__.py
    2. 1.2. setup.py
  2. 2. 使用到的命令
    1. 2.1. 打包
    2. 2.2. 上传至Artifactory
    3. 2.3. 引用
© 2019 – 2020 作者拥有版权,转载请注明出处