国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
制作python模塊安裝包(轉(zhuǎn))

python的第三方模塊越來越豐富,涉及的領(lǐng)域也非常廣,如科學(xué)計算、圖片處理、web應(yīng)用、GUI開發(fā)等。當(dāng)然也可以將自己寫的模塊進(jìn)行打包或發(fā)布。一簡單的方法是將你的類包直接copy到python的lib目錄,但此方式不便于管理與維護(hù),存在多個python版本時會非常混亂?,F(xiàn)介紹如何編寫setup.py來對一個簡單的python模塊進(jìn)行打包。

一、編寫模塊
進(jìn)入項目目錄
#cd /home/pysetup
#vi foo.py
#! /usr/bin/env python

#coding=utf-8

class MyLib():

    def __init__(self):

        self.str = "hello!"

   

    def print_log(self):

        print self.str

       

    def printBlog(self):

        print self.str.swapcase();
二、編寫setup.py
#vi setup.py
#! /usr/bin/env python

#coding=utf-8

from distutils.coreimport setup

setup(

    name='MyLib',

    version='1.0',

    description='My Lib disribution Utility',

    author='Edison',

    author_email='eddy.wd5@gmail.com',

    url='http://hi.baidu.com/gylxue',

    py_modules=['mylib'],

   

)

更多參數(shù)說明見表:



三、setup.py參數(shù)說明


#python setup.py build     # 編譯
#python setup.py install     #安裝
#python setup.py sdist       #生成壓縮包(zip/tar.gz)
#python setup.py bdist_wininst   #生成NT平臺安裝包(.exe)
#python setup.py bdist_rpm #生成rpm包


或者直接"bdist 包格式",格式如下:


#python setup.py bdist --help-formats
   --formats=rpm       RPM distribution
   --formats=gztar     gzip'ed tar file
   --formats=bztar     bzip2'ed tar file
   --formats=ztar     compressed tar file
   --formats=tar       tar file
   --formats=wininst   Windows executable installer
   --formats=zip       ZIP file


四、打包
#python setup.py sdist


running sdist

warning: sdist: manifest template 'MANIFEST.in' does not exist (using defaultfile list)
warning: sdist: standard file not found: should have one of README, README.txt

writing manifest file 'MANIFEST'
creating MyLib -1.0
making hard links in MyLib -1.0...
hard linking foo.py -> MyLib -1.0
hard linking setup.py -> MyLib -1.0
creating dist
tar -cf dist/ MyLib -1.0.tar MyLib -1.0
gzip -f9 dist/MyLib -1.0.tar
removing ‘MyLib -1.0' (and everything under it)


提示兩條warning可以忽略,不影響打包,當(dāng)然一個完善的項目必須有README及MANIFEST.in(項目文件清單)文件。
#ls dist

MyLib -1.0.tar.gz

五、安裝
#tar -zxvf MyLib -1.0.tar.gz
#cd MyLib -1.0.tar.gz
#python setup.py install (此命令大家再熟悉不過了)


running install
running build
running build_py
creating build/lib.linux-x86_64-2.6
copying mylib.py -> build/lib.linux-x86_64-2.6
running install_lib
copying build/lib.linux-x86_64-2.6/ mylib.py ->/usr/local/lib/python2.6/dist-packages
byte-compiling /usr/local/lib/python2.6/dist-packages/ mylib.py to mylib.pyc
running install_egg_info
Writing /usr/local/lib/python2.6/dist-packages/ mylib -1.0.egg-info


六、測試


>>> from mylib import MyLib
>>> app= MyLib ()
>>> app.

If your package provider didn't produce a setup.pyuninstall method then,more often than not,

you can just manually remove the package fromyour Python's site-packages directory.

This will be located at /usr/lib/python2.5/site-packages or equivalent for your distro and version ofPython.

Within that there will be either a directoryor a .eggfile corresponding to the package's name.

Simply delete that.There are some instanceswhere packages will install stuff elsewhere.

Django for instance installs django-admin.py to /usr/sbin. Y


一些插件(例如 SpamFilter)可以作為.egg文件進(jìn)行下載, 可以和easy_install程序一起安裝:

easy_install TracSpamFilter

如果easy_install不在你的系統(tǒng)上,請參考上節(jié)中的要求來安裝. Windows用戶還需要將Python安裝包的Scripts目錄, 例如C:\Python23\Scripts, 添加到PATH環(huán)境變量中. 更多信息,請參考 easy_install Windows說明.

如果安裝完一個egg后, Trac報告權(quán)限錯誤, 而你不想為Web服務(wù)器提供一個可寫的egg緩存目錄,你只需解壓這個egg來繞開這個問題.使用--always-unzip選項:

easy_install --always-unzip TracSpamFilter-0.2.1dev_r5943-py2.4.egg

你應(yīng)該用與egg相同的名字作為目錄名(包括結(jié)尾的.egg), 目錄中是解壓后的內(nèi)容.

Trac也會搜索全局安裝的插件(0.10版本后),參見 TracIni#GlobalConfiguration.

從源代碼

easy_install從源代碼的快照安裝. 只需要Subversion的URL或者源代碼的壓縮包(tarball/zip):

easy_install http://svn.edgewall.com/repos/trac/sandbox/spam-filter啟用插件

不像只安裝在環(huán)境目錄中的那些插件, 你需要通過trac.ini來啟用全局安裝的插件. 這是在配置文件的[components]段中完成的, 例如:

[components]tracspamfilter.* = enabled

選項名是插件的Python安裝包.插件的相應(yīng)文檔中應(yīng)該明確指定, 但通過查看源代碼輕易找到(找包含__init__.py的頂級目錄).

注意:安裝完插件后,你還需要重啟Apache.

卸載

easy_install 或 python setup.py 還沒有卸載功能. 然而, 刪除全局安裝插件egg的方法通常是:

運行

如果你對egg的位置不確定,這里有一個小技巧來定位egg(或任意包)- 用插件使用的名字空間(跟啟用插件一樣)替換:

>>> import myplugin>>> print myplugin.__file__/opt/local/python24/lib/site-packages/myplugin-0.4.2-py2.4.egg/myplugin/__init__.pyc


本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
python技巧26[python的egg包的安裝和制作]
為R6300v2編譯python
Python深入:Distutils發(fā)布Python模塊
64位CentOS下安裝python的PIL模塊
easy-install
Python包管理工具setuptools詳解
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服