1、首先将写好注释的代码保存在一个文件夹nester下
![1858755.html](https://www.xuebuyuan.com/1858755.html)
2、在这个文件夹下创建一个文件setup.py,用来编辑模块的元数据
![1858755.html](https://www.xuebuyuan.com/1858755.html)
from distutils.core import setup #从发布工具导入setup函数
setup(
name ='nester',
version ='1.0.0',
py_modules =['nester'],
author ='jqm',
author_email='jqm2009@gmail.com',
url ='http://www.headfirstlabs.com',
description ='A simple printer of nested lists',
)
以上author ~ description 都可以根据个人需求更改
![smile.gif](http://static.blog.csdn.net/xheditor/xheditor_emot/default/smile.gif)
3、然后就是构建发布了
i. 打开“运行”—>键入cmd,回车
ii. 在命令行中键入nester文件夹的路径,例如:
C:\Users\Administrator>cd D:\python\nester
从网上看到有个简单的方法,在cd后加一空格,然后直接把nester文件夹用鼠标拖到cmd窗口,
这样文件夹的位置就会直接显示到里面,就不用一点一点敲了
![smile.gif](http://static.blog.csdn.net/xheditor/xheditor_emot/default/smile.gif)
iii. 输入python.exe路径及命令:
D:\python\nester>d:\python\python.exe setup.py sdist
如果python.exe安装路径与nester文件一致,可以用下面的格式
D:\python\nester>py setup.py sdist
回车后出现:
![3c41698d32b2ee557a7c2c8e6f560355.png](https://img-blog.csdnimg.cn/img_convert/3c41698d32b2ee557a7c2c8e6f560355.png)
目前还不知道为什么会出现这个错误![fastcry.gif](http://static.blog.csdn.net/xheditor/xheditor_emot/default/fastcry.gif)
此时,nester文件夹中会出现一个nester-1.0.0的文件夹
![1858755.html](https://www.xuebuyuan.com/1858755.html)
还有一个
MANIFEST文件,用记事本打开后,里面记录了发布中的文件列表
iiii.将发布安装到本地副本中,输入python路径 setup.py install 或者:
D:\python\nester>py setup.py install
回车,得到:
![50f34624cc9da6bce21204c348b31b25.png](https://img-blog.csdnimg.cn/img_convert/50f34624cc9da6bce21204c348b31b25.png)
此时,nester文件夹中,变成:
![65ea4b11957a9af49b2a2ac3fcb25302.png](https://img-blog.csdnimg.cn/img_convert/65ea4b11957a9af49b2a2ac3fcb25302.png)
本来应该还有一个dist文件夹的,但是因为上一个步骤出现了问题,创建失败![fastcry.gif](http://static.blog.csdn.net/xheditor/xheditor_emot/default/fastcry.gif)
其中,build文件夹有一个lib子文件夹,里面包含着nester.py代码
后来我换了台电脑操作,发现上述出现的问题没有复现,这个……呵呵,不知道有没有大神知道的。
![876dd602291d15e7645e462f6b64866c.png](https://img-blog.csdnimg.cn/img_convert/876dd602291d15e7645e462f6b64866c.png)
安装本地副本:
![28659040898394ff5c2cdf8b9e941299.png](https://img-blog.csdnimg.cn/img_convert/28659040898394ff5c2cdf8b9e941299.png)
文件夹结果:
![b89a269eb6ba893166b5c55b45c5ca0d.png](https://img-blog.csdnimg.cn/img_convert/b89a269eb6ba893166b5c55b45c5ca0d.png)
其中,dist文件夹里是打包好的文件:
![1f123bd584fef2733f3b41d58f80ed76.png](https://img-blog.csdnimg.cn/img_convert/1f123bd584fef2733f3b41d58f80ed76.png)