How to package your python codes?

Here is the detail introduction:

https://packaging.python.org/distributing/

Basicly, to create a python package, you just need to do the following steps:

1. Create a setup.py and a setup.cfg (optional) file, here is an example:

import re
from distutils.core import setup

setup(name=‘packageName‘,
      version=‘1.0.0.dev0‘,
      description=‘Package description‘,
      author=‘YourName‘,
      author_email=‘[email protected]‘,
      packages=[‘packageName‘],      install_requires=[‘Mako‘],
      include_package_data=True,
      zip_safe = False
      )

2. Create a MANIFEST.in file.

include *.txt
recursive-include docs *
recursive-include folder_name *

3. Run command.

Python setup.py sdist

To upload the package to your pypi server

1. Create a .pypirc file in C:\Users\<yourname>, and refer to the example

[distutils]
index-servers:
   primary
   secondary
[primary]
repository: http://primary.domain
username: whoami
password: guessme
[secondary]
repository: http://secondary.domain
username: whoami
password: guessme

2. Upload your package.

Upload your package to primary pypi server, just use the command below:

Python setup.py upload primary

But the recommend way to upload your packages is using Twine.

See https://packaging.python.org/distributing/#upload-your-distributions

3. Also, you can create your own uploader, the best practice way to upload your package is

Build Your package --> Test Your Package (Code Coverage, UT) --(If Test Pass)--> Upload to the Pypi repository.

时间: 2024-08-28 13:43:49

How to package your python codes?的相关文章

About Module and Package in Python

关于Python Package下的Module import方式[转]

2012年有一个目标我没有达成,那就是深入学习和使用Python语言.这个目标被其他学习任务和工作无情的抢占了,当然最主要的原因还是我重视不够^_^. 近期恰逢有一些Python工程的开发工作要做,就顺便略微深入地学习了一下Python:看了几本Python的英文大部头,比如<Learning Python 4th Edition>.<Python Essential Reference 4th Edition>.<Programming Python 4th Edition

PyCharm中Directory与Python package的区别

PyCharm中Directory与Python package的区别 对于Python而言,有一点是要认识明确的,python作为一个相对而言轻量级的,易用的脚本语言(当然其功能并不仅限于此,在此只是讨论该特点),随着程序的增长,可能想要把它分成几个文件,以便逻辑更加清晰,更好维护,亦或想要在几个程序中均使用某个函数,而不必将其复制粘贴到所有程序中. 为了支持这一点,Python有一种方法将定义函数放在一个文件中,并在脚本中使用它们,这样的文件叫做模块,一个模块中的定义可以被导入到其他模块,或

Python入门之PyCharm中目录directory与包package的区别

对于Python而言,有一点是要认识明确的,python作为一个相对而言轻量级的,易用的脚本语言(当然其功能并不仅限于此,在此只是讨论该特点),随着程序的增长,可能想要把它分成几个文件,以便逻辑更加清晰,更好维护,亦或想要在几个程序中均使用某个函数,而不必将其复制粘贴到所有程序中. 为了支持这一点,Python有一种方法将定义函数放在一个文件中,并在脚本中使用它们,这样的文件叫做模块,一个模块中的定义可以被导入到其他模块,或者主模块中. 简单来说在python中模块就是指一个py文件,如果我们将

PyCharm中Dictionary与Python package的区别

Dictionary Dictionary在pycharm中就是一个文件夹,放置资源文件,对应于在进行JavaWeb开发时用于放置css/js文件的目录,或者说在进行物体识别时,用来存储背景图像的文件夹.该文件夹其中并不包含_ _ init.py_ _文件 Python package 对于Python package 文件夹而言,与Dictionary不同之处在于其会自动创建_ _ init.py_ _文件. 简单的说,python package就是一个目录,其中包括一组模块和一个_ _ i

ros2中创建一个python package

完整的python package的目录结构如下: source /opt/ros/dashing/setup.bash cd ros2_ws/src && ros2 pkg create Delete CMakeLists.txt , create setup.py and setup.cfg and edit package.xml setup.py内容参考: from setuptools import setup package_name = 'ros2_demo_py' setu

Python著名的lib和开发框架(均为转载)

第一,https://github.com/vinta/awesome-python Awesome Python A curated list of awesome Python frameworks, libraries, software and resources. Inspired by awesome-php. Awesome Python Admin Panels Algorithms and Design Patterns Anti-spam Asset Management A

Python框架、库以及软件资源汇总

转自:http://developer.51cto.com/art/201507/483510.htm 很多来自世界各地的程序员不求回报的写代码为别人造轮子.贡献代码.开发框架.开放源代码使得分散在世界各地的程序员们都能够贡献他们的代码与创新. Python就是这样一门受到全世界各地开源社区支持的语言.Python可以用来开发各种小工具软件.web应用.科学计算.数据分析等等,Python拥有大量的流行框架,比如Django.使用Python框架时,可以根据自己的需求插入不同的模块,比如可以用S

Machine and Deep Learning with Python

Machine and Deep Learning with Python Education Tutorials and courses Supervised learning superstitions cheat sheet Introduction to Deep Learning with Python How to implement a neural network How to build and run your first deep learning network Neur