简要介绍Python模块的编译与安装。
1. setup.py编写
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. 示例脚本
# coding=utf8
__metaclass__ = type
__author__ = 'dbloop'
print 'hello word!'
3. 编译
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. 安装
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文件可删除。
来源:oschina
链接:https://my.oschina.net/u/2690292/blog/661856