1. Make the package file you want to share (there must be an __init__ file).
This method can automatically create the __init__ file.
The __init__ file code is as follows
from . import receive_message
from . import send_message
The receive_message file code is as follows (define the module code yourself)
def receive():
return "返回了数据"
The send_message file code is as follows (define the module code yourself)
def send(text):
print("正在发送%s" % text)
2. Create a setup.py file
where the setup file code is as follows
from distutils.core import setup
setup(name="gg_message", # 包名
version="1.0", # 版本
description="gg‘s发送和接收消息模块", # 描述信息
long_description="完整的发送和接收消息模块", # 完整描述信息
author="gg", # 作者
author_email="[email protected]", # 作者邮箱
url="https://blog.csdn.net/qq_45156021?type=blog", # 主页
py_modules=["gg_message.receive_message", # 包.模块名(要写所有的)
"gg_message.send_message"]
# packages=find_packages(), # 需要处理的包目录(包含__init__.py的文件夹)
# platforms="any", # 适用的软件平台列表
# install_requires=[], # 需要安装的依赖包
# 项目里会有一些非py文件,比如html和js等,这时候就要靠include_package_data和package_data来指定了。
# scripts=[], # 安装时需要执行的脚本列表
# entry_points={
# 动态发现服务和插件
# 'console_scripts': [
# 'jsuniv_sllab = jsuniv_sllab.help:main'
# ]
)
3. Next, run on the Terminal terminal. python setup.py build
After running, the build file package appears under the left file tree, as shown in Figure 3 above.
4. Next, python setup.py sdist
after running on the Terminal terminal, the dist file package and "yourself Defined file package name.egg-info”
5. Unzip the file.
Open the copy path on the computer and open the dist file in this folder.
Unzip this file
and enter cmd to open the background input python 自己定义的python文件名.py install
.
For example, in this example, it is python setup.py install
necessary to pay attention here One point:
first copy the file path in 1, enter cd and the path you just copied in the terminal, then enter this folder, and then
enter python setup.py install
the installation file
6, use the module
and then you can find us under Setting The package made by yourself
Then import the package in the software to use the functions in the module, that is, the functions in the system.
After running, the console outputs
7, and the module is uninstalled.
Find this directory. If the AppData directory cannot be found, click View-Show-Hidden Items in the previous folder
to delete the gg_message and egg-info files. If
you look again, there is no gg_message file
and the imported file will also report error
8. , what are third-party modules and pip
1. What does third-party module mean in python?
Third-party modules usually refer to Python packages/modules developed by well-known third-party teams and widely used by programmers
2. What is pip?
Pip is a general Python package management tool that provides Python package search and download , installation, uninstallation and other functions