What is module and How to publish module in Python?
-
Overview
In Python, a module is a self-contained file with Python statements and definitions,
file.py
can be considered as a module namedfile
.“PyPI” should be pronounced like “pie pea eye”, ***Python Package Index***, is also known as the Cheese Shop. It is the official third-party software repository for Python, just like CPAN is the repository for Perl. Some package manager’s such as
pip
, use PyPI as the default source for packages and their dependencies. -
python -m
The
python
interpreter program has an-m
option that allows you to specify amodule
name instead of afile
name.$ python hello.py # is equal to $ python -m hello
One advantage of the latter is that it allows you to call modules that are built into Python as well.
-
Publish an Open-Source Python Package to PyPI
-
Naming Your Package
All packages on PyPI need to have unique names. Use the PyPI search to check if a name is already taken.
You can use different names for your package on PyPI and when importing.
-
Configuring Your Package
In order for your package to be uploaded to PyPI, you need to provide some basic information about it. This information is typically provided in the form of a
setup.py
file.The
setup.py
file should be placed in the top folder of your package.The parameters that are 100% necessary in the call to setup() are name/version/packages.
-
Documenting your package
README or website or something else.
-
Versioning your package
If you want to update your package on PyPI, you need to increase the version number first.
You may need to specify the version in different files inside your project, you can use a tool called Bumpversion to keep consitent.
-
Adding files to your package
Adding files not source code files.
include_package_data
-
Prepare for Publishing to PyPI
Resigter your account on PyPI and TestPyPI.
To upload your package to PyPI, you’ll use a tool called Twine.
-
Building your package
Packages on PyPI are not distributed as plain source code. Instead, they are wrapped into distribution packages. The most common formats for distribution packages are source archives and Python wheels.
$ python setup.py sdist bdist_wheel # to create a source archive and a wheel
-
Testing your package
-
Uploading your package
$ twine upload --repository-url https://test.pypi.org/legacy/ dist/*
-
-
References
上一篇: centos 7 安装latest python 2.7.14
下一篇: Java语言的基础是什么
推荐阅读
-
python进阶教程之模块(module)介绍
-
Python 常用的几种安装Module方式
-
Python安装Imaging报错:The _imaging C module is not installed问题解决方法
-
python提示No module named images的解决方法
-
解决Python源码编译时提示:ModuleNotFoundError: No module named ‘distutils.command‘
-
python开发中module模块用法实例分析
-
下载python中Crypto库报错:ModuleNotFoundError: No module named ‘Crypto’的解决
-
解决python "No module named pip"的问题
-
Python 使用redis报:No module named redis问题
-
解决Python找不到ssl模块问题 No module named _ssl的方法