簡要介紹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