1.模块的位置
现在当前路径查找,再到系统路径/usr/lib/python3.5/查找,再到其他系统路径查找
2.模块发布
1)模块目录结构
Msg├── __init__.py├── recvmsg.py└── sendmsg.py
2)编辑setup.py文件
py_modules需指明所需包含的py文件
from distutils.core import setupsetup(name="dongGe", version="1.0", description="dongGe's module", author="dongGe", py_modules=['Msg.sendmsg','Msg.recvmsg'])
.├── Msg│ ├── __init__.py│ ├── recvmsg.py│ └── sendmsg.py└── setup.py
3) .构建模块
python setup.py build
### 构建后目录结构.├── build│ └── lib│ └── Msg│ ├── __init__.py│ ├── recvmsg.py│ └── sendmsg.py├── Msg│ ├── __init__.py│ ├── recvmsg.py│ └── sendmsg.py└── setup.py
4)生成发布压缩包
python setup.py sdist
## 打包后,生成最终发布压缩包dongGe-1.0.tar.gz , 目录结构.├── build│ └── lib│ └── Msg│ ├── __init__.py│ ├── recvmsg.py│ └── sendmsg.py├── dist│ └── dongGe-1.0.tar.gz├── MANIFEST├── Msg│ ├── __init__.py│ ├── recvmsg.py│ └── sendmsg.py└── setup.py
5)压缩包复制到其他地方可以使用
dongGe-1.0.tar.gz
python@ubuntu:~/pythonS6/python基础10/03-发布模块$ cp dist/dongGe-1.0.tar.gz ~/Desktop/python@ubuntu:~/pythonS6/python基础10/03-发布模块$ cd ~/Desktop/python@ubuntu:~/Desktop$ lsdongGe-1.0.tar.gz
3.模块的安装
1)下载模块
python@ubuntu:~/Desktop$ lsdongGe-1.0.tar.gz
2)解压
python@ubuntu:~/Desktop$ tar -xvf dongGe-1.0.tar.gz
.├── dongGe-1.0│ ├── Msg│ │ ├── __init__.py│ │ ├── recvmsg.py│ │ └── sendmsg.py│ ├── PKG-INFO│ └── setup.py└── dongGe-1.0.tar.gz
3)PKG-INFO文件?? 基本信息
python@ubuntu:~/Desktop$ cat dongGe-1.0/PKG-INFO Metadata-Version: 1.0Name: dongGeVersion: 1.0Summary: dongGe's moduleHome-page: UNKNOWNAuthor: dongGeAuthor-email: UNKNOWNLicense: UNKNOWNDescription: UNKNOWNPlatform: UNKNOWN
4) 进入文件夹,执行命令python setup.py install
python@ubuntu:~/Desktop/dongGe-1.0$ sudo python3 setup.py installrunning installrunning buildrunning build_pyrunning install_librunning install_egg_infoRemoving /usr/local/lib/python3.5/dist-packages/dongGe-1.0.egg-infoWriting /usr/local/lib/python3.5/dist-packages/dongGe-1.0.egg-info #安装成功
5)引入模块。执行验证
In [3]: import MsgIn [4]: Msg.sendmsg.test1()--sendmsg-test1---