使用 Setup 將Python 代碼 打包

來源:互聯網
上載者:User

標籤:檔案夾   class   orm   目錄   sse   --help   平台   file   .exe   

完成源碼後將代碼打成安裝包:

1. 我的原始碼結構如下:

pack

|---src

  | - common ---http

        ---user

  | - lib

  | - factory.py

 

2. 實現setup.py

#!/usr/bin/env python3# -*- coding: utf-8 -*-from distutils.core import setupsetup(    name=‘sdk‘,    version=‘1.0‘,    description=‘sdk for di input , output and param‘,    author=‘sam‘,    author_email=‘sam@qq.com‘,    url=‘‘,    license=‘No License‘,    platforms=‘python 2.7‘,    py_modules=[‘factory‘],    package_dir={‘‘: ‘pack‘},    packages=[‘lib‘, ‘common.http‘])

執行

python setup.py sdist

setup.py 同級目錄產生一個dist檔案夾,裡面是 sdk1.0.tar.gz

之後就可以解壓

解壓後安裝:

python setup.py install 

注:使用 setup.py沒有卸載功能,如果需要卸載則要手動刪除

也可使用: -- record 記錄安裝檔案的目錄 

python setup.py install --record file.txt

卸載就可以使用指令碼,實現自動安裝和卸載

注 1:

setup.py參數說明

 

#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

 

注2: setup參數:

  1. name 打包名稱 
  2. version 版本
  3. ....
  4. playforms 所支援的平台 ,例中只支援2.7
  5. package_dir 源碼所在目錄 
  6. packages 源碼目錄下那些目錄要被打包
  7. py_modules 需要打包的模組
  8. requires 定義相依模組 
  9. ... 

具體參數可參見官網

 

使用 Setup 將Python 代碼 打包

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.