简要介绍Python模块的编译与安装。python
1. setup.py编写shell
from distutils.core import setup setup( name='hello', version='1.0', description='A simple example', author='dbloop', author_email='984513956@qq.com', url='http://my.oschina.net/dbloop/blog', py_modules=['hello'] )
2. 示例脚本oop
# coding=utf8 __metaclass__ = type __author__ = 'dbloop' print 'hello word!'
3. 编译ui
C:\Users\Administrator\distutilsDir\test001>python setup.py build running build running build_py creating build creating build\lib copying hello.py -> build\lib
4. 安装url
C:\Users\Administrator\distutilsDir\test001>python setup.py install running install running build running build_py running install_lib copying build\lib\hello.py -> C:\Python27\Lib\site-packages byte-compiling C:\Python27\Lib\site-packages\hello.py to hello.pyc running install_egg_info Writing C:\Python27\Lib\site-packages\hello-1.0-py2.7.egg-info
至此,hello.py文件被安装到了本机python目录中,并生成python.pyc编译文件,python.py文件可删除。.net