How to using PyPI publish a Python package
How to using PyPI publish a Python package
PyPI & Python package

main
make a file that can be both imported as a module and run as a script.
To do this, place script code inside if name == "main".
This ensures that it won't be run if the file is imported.
# module.py
def function():
print("This is a module function")
if __name__=="__main__":
print("This is a script")
# app.py
from module import function
function();
$ python3 module.py
# "This is a script"
$ python3 app.py
# This is a module function
When the Python interpreter reads a source file, it executes all of the code it finds in the file.
Before executing the code, it defines a few special variables.
For example, if the Python interpreter is running that module (the source file) as the main program, it sets the special name variable to have a value "main". If this file is being imported from another module, name will be set to the module's name.
directory structure
project/
LICENSE.txt
README.txt
setup.py
emoji/
__init__.py
module.py
module2.py
...
In Python, the term packaging refers to putting modules you have written in a standard format, so that other programmers can install and use them with ease.
This involves use of the modules setuptools and distutils.
The first step in packaging is to organize existing files correctly.
Place all of the files you want to put in a library in the same parent directory.
This directory should also contain a file called __init__.py, which can be blank but must be present in the directory.
This directory goes into another directory containing the readme and license, as well as an important file called setup.py.
init.py
setup.py
This contains the information necessary to assemble the package so it can be uploaded to PyPI and installed with pip (name, version, etc.).
from distutils.core import setup
setup(
name='project',
version='0.1dev',
packages=['emoji',],
license='MIT',
long_description=open('README.txt').read(),
)
After creating the setup.py file, upload it to PyPI, or use the command line to create a binary distribution (an executable installer).
To build a source distribution, use the command line to navigate to the directory containing setup.py, and run the command python setup.py sdist.
Run python setup.py bdist or, for Windows, python setup.py bdist_wininst to build a binary distribution.
Use python setup.py register, followed by python setup.py sdist upload to upload a package.
Finally, install a package with python setup.py install.
# build a source distribution
$ python setup.py sdist
# upload a package
$ python setup.py register
# build a binary distribution
$ python setup.py bdist
# install a package
$ python setup.py install
Packaging
package a Python script to executable file
However, many computer users who are not programmers do not have Python installed.
Therefore, it is useful to package scripts as executable files for the relevant platform, such as the Windows or Mac operating systems.
This is not necessary for Linux, as most Linux users do have Python installed, and are able to run scripts as they are.
for Windows, use py2exe, PyInstaller, cx_Freeze
For Macs, use py2app, PyInstaller, cx_Freeze
Python Style Guide
Zen of Python
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
PEP 8
Python Enhancement Proposals (PEP)
PEP 8 is a style guide on the subject of writing readable code.
refs
https://pypi.org/manage/projects/
https://www.sololearn.com/Course/Python/
https://www.sololearn.com/Play/Python
https://www.sololearn.com/Certificate/Python/jpg/
https://www.sololearn.com/Profile/3476348/Python
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
How to using PyPI publish a Python package的更多相关文章
- Python package下载中遇到ReadTimeoutError: HTTPSConnectionPool?
问题描述: Python package下载中遇到ReadTimeoutError: HTTPSConnectionPool? 问题解决: 方法1:继续重复下载 pip install virtual ...
- 在pypi上发布python包详细教程
使用Python编程中Python的包安装非常方便,一般都是可以pip来安装搞定:pip install <package name>,我们自己写的python也可以发布在pypi上,很简 ...
- ros2中创建一个python package
完整的python package的目录结构如下: source /opt/ros/dashing/setup.bash cd ros2_ws/src && ros2 pkg crea ...
- 利用setuptools发布Python程序到PyPI,为Python添砖加瓦
pip install的东西从哪里来的? 从PyPI (Python Package Index)来的,官网是: https://pypi.python.org/pypi/执行pip install ...
- Python package钓鱼
Python package钓鱼 一.概述 在收录该文之后,知道创宇404安全实验室对该文中所提到的攻击方式进行跟进.整理分析原作者公布的钓鱼数据.值得一提的是,在跟进的过程中,我们发现了新的钓鱼 ...
- Ghost.py 0.1b3 : Python Package Index
Ghost.py 0.1b3 : Python Package Index Ghost.py 0.1b3 Download Ghost.py-0.1b3.tar.gz Webkit based web ...
- pyrailgun 0.24 : Python Package Index
pyrailgun 0.24 : Python Package Index pyrailgun 0.24 Download pyrailgun-0.24.zip Fast Crawler For Py ...
- qrcode 4.0.4 : Python Package Index
qrcode 4.0.4 : Python Package Index qrcode 4.0.4 Download qrcode-4.0.4.tar.gz QR Code image generato ...
- bottle-session 0.3 : Python Package Index
bottle-session 0.3 : Python Package Index bottle-session 0.3
随机推荐
- 亿级用户下的新浪微博平台架构 前端机(提供 API 接口服务),队列机(处理上行业务逻辑,主要是数据写入),存储(mc、mysql、mcq、redis 、HBase等)
https://mp.weixin.qq.com/s/f319mm6QsetwxntvSXpKxg 亿级用户下的新浪微博平台架构 炼数成金前沿推荐 2014-12-04 序言 新浪微博在2014年3月 ...
- 使用jiffies的时间比较函数time_after、time_before
1. jiffies简介 首先,操作系统有个系统专用定时器(system timer),俗称滴答定时器,或者系统心跳. 全局变量jiffies取值为自操作系统启动以来的时钟滴答的数目,在头文件< ...
- 静默安装Oracle也没那么恐怖
几种必须静默安装的情况 服务器为了减少资源占用,没安装图形组件 不能进入机房,只能远程SSH 想炫(Z)耀(B),静默安装显得有技术含量 磁盘分区要求 如没有特别要求,装机时可按如下分区比较好管理 / ...
- 31-1.解决service iptables save出错
CentOS 7.x开始,CentOS开始使用systemd服务来代替daemon,原来管理系统启动和管理系统服务的相关命令全部由systemctl命令来代替.service命令只保留下了极少部分使用 ...
- pytest测试框架+jenkins结合pytest+jenkins邮件通知配置
刚刚做完一个项目,由于这是一个方案项目,而不是产品,所以各种准备很不充分,很多公司的能力不能复用,整个团队又都是新员工,而且有部分实习生,匆忙上马,今天对我的自动化框架做一个回溯 自动化测试框架的选择 ...
- Spring Boot 2.x基础教程:使用JTA实现多数据源的事务管理
在一个Spring Boot项目中,连接多个数据源还是比较常见的.之前也介绍了如何在几种常用框架的场景下配置多数据源,具体可见: Spring Boot 2.x基础教程:JdbcTemplate的多数 ...
- canal-adapter1.1.14最新版本安装的过程中出现的NullPointerException异常
记录一下我在安装 canal-adapter1.1.14最新版本安装的过程中出现的NullPointerException异常 以下是我的canal-adapter/logs文件夹内adapter.l ...
- this.$nextTick( 回调函数 )的作用
首先要明确几个概念 1.Vue的核心思想 数据驱动 和 组件化系统 2.同步和异步 在没有特殊情下,程序一般先执行同步代码,等待同步执行完之后,执行异步代码 下面进入正题,首先贴出程序片段: 在该段代 ...
- DICOM医学文件的解析
最近导师一直让做智慧医疗的一个项目,这里面涉及到DICOM格式的文件处理,在这里分享一下自己学到的关于DCM文件的一些内容. DICOM DICOM(DigitalImaging andCommuni ...
- CF-1332 F. Independent Set
F. Independent Set 题意 一颗 n 个节点的树,求出每个\(edge-induced~subgraph\)的独立集个数之和. \(edge-induced~subgraph\)含义是 ...