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
随机推荐
- status http status code 状态码
RFC 6585 - Additional HTTP Status Codes https://tools.ietf.org/html/rfc6585 https://developer.mozill ...
- 不占用额外内存空间能否做到 将图像旋转90度 N × N矩阵表示的图像,其中每个像素的大小为4字节
给定一幅由N × N矩阵表示的图像,其中每个像素的大小为4字节,编写一种方法,将图像旋转90度. 不占用额外内存空间能否做到? 示例 1: 给定 matrix = [ [1,2,3], [4,5,6] ...
- gitignore 不起作用的解决办法 不再跟踪 让.gitignore生效,跟踪希望被跟踪的文件
实践 # https://git-scm.com/docs/gitignore https://git-scm.com/docs/gitignore 不跟踪log目录下的所有文件,但需要保留这个文件夹 ...
- Python的交互模式和直接运行.py文件有什么区别
使用文本编辑器 - 廖雪峰的官方网站 https://www.liaoxuefeng.com/wiki/1016959663602400/1017024645952992 直接输入python进入交互 ...
- Spring Boot 系列总结
Spring Boot 系列总结 1.SpringBoot自动装配 1.1 Spring装配方式 1.2 Spring @Enable 模块驱动 1.3 Spring 条件装配 2.自动装配正文 2. ...
- oracle 常用语法()
一ORACLE的启动和关闭 1在单机环境下 2在双机环境下 Oracle数据库有哪几种启动方式 1startup nomount 2startup mount dbname 3startup open ...
- Jenkins (1、自动化发布war包、2、自动化发布nodejs)
1.持续集成javaweb 首先咱们需要安装一个 Jenkins,这个就不必多说了,晚上一搜索一大把,然后安装各种插件,配置各种环境变量, 今天我的实验环境是 使用Jenkins 拉取gitlap上项 ...
- cachedThreadPool缓存线程池
package com.loan.modules.common.util; import java.util.concurrent.BlockingQueue; import java.util.co ...
- ES6(三) Promise 的基本使用方式
基本用法 关于Promise的资料,网上有很多了,这里简单粗暴一点,直接上代码. 假设我们要做一个访问后端API的函数,那么我们可以这样模拟一下. const mySend = (url, data) ...
- EF6.2加载速度慢的解决方案
最近的项目中一直有反馈,EF在第一次启动之后调用的话,加载速度很慢,在网上搜索了一下,基本就是三种解决方案. 在程序启动的时候将映射视图缓存下来. 使用Ngen生成EF的本地镜像. IIS8内置功能 ...