如何製作python安裝模組(setup.py)
python setup.py --help-commands
Python模組的安裝方法:
1. 單檔案模組:直接把檔案拷貝到$python_dir/lib
2. 多檔案模組,帶setup.py:python setup.py install
3. egg檔案,類似Java的jar:
1) 下載ez_setup.py,執行python ez_setup
2) easy_install *.egg
雖然Python的模組可以拷貝安裝,但是一般情況下推薦製作一個安裝包,即寫一個setup.py檔案來安裝。
setup.py檔案的使用:
% python setup.py build #編譯
% python setup.py install #安裝
% python setup.py sdist #製作分發包
% python setup.py bdist_wininst #製作windows下的分發包
% python setup.py bdist_rpm
setup.py檔案的編寫:
setup.py中主要執行一個 setup函式,該函式中大部分是描述性東西,最主要的是packages引數,列出所有的
package,可以用自帶的find_packages來動態獲取package。所以setup.py檔案的編寫實際是很簡單的。
簡單的例子:
setup.py檔案:
from setuptools import setup, find_packages
setup(
name="mytest",
version="0.10",
description="My test module",
author="Robin Hood",
url="http://www.csdn.net",
license="LGPL",
packages= find_packages(),
scripts=["scripts/test.py"],
)
mytest.py檔案:
import sys
def get():
return sys.path
scripts/test.py檔案:
import os
print os.environ.keys()
setup中的scripts表示將該檔案放到 Python的Scripts目錄下,可以直接用。OK,簡單的安裝成功,可以執行所列舉的命令生成安裝包,或者安裝該python包。
本機測試成功(win32-python25)!
轉自:
http://blog.csdn.net/foyuan/archive/2007/11/14/1883924.aspx
http://www.okpython.com/bbs/thread-3103-1-1.html
相關文章
- Python 模組的製作,釋出,安裝Python
- python openssl模組如何安裝?Python
- python 模組安裝Python
- Python模組安裝Python
- Python安裝selenium模組Python
- python(pip)包/模組:如何離線安裝?Python
- Python如何檢視安裝了哪些模組?Python
- python 安裝模組的方法Python
- Python安裝模組有哪些方法?Python
- Python模組、第三方模組安裝、模組匯入教程Python
- python模組安裝目錄在哪裡Python
- Python paramiko模組的安裝與使用Python
- 怎樣安裝python的GPIO模組Python
- U盤如何製作win10安裝盤|win10安裝U盤製作方法Win10
- PyMySQL模組安裝MySql
- Python:檢視已安裝模組 和 檢視可匯入模組Python
- 軟測WebUI Python安裝selenium模組失敗,用VSCode安裝成功WebUIPythonVSCode
- 隨身碟如何製作win10安裝盤|win10安裝隨身碟製作方法Win10
- php 安裝zip模組PHP
- windows 安裝 Pillow 模組Windows
- Python 庫/模組的pip安裝和IPython的使用Python
- python3安裝編譯_tkinter模組丟失Python編譯
- Python怎麼安裝第三方模組Python
- Python筆記之paramiko模組安裝和使用示例Python筆記
- Python安裝cx_Oracle模組遇到的問題PythonOracle
- Python 精靈模組製作的月滿西樓李清照詞 MVPython
- pip 命令安裝模組包
- pip進行模組安裝
- Python3 全自動更新已安裝的模組Python
- Python表格處理模組xlrd在Anaconda中的安裝Python
- pip高階玩法,讓python模組安裝飛起來Python
- Python 精靈模組製作的美女與圖章虛像效果.pyPython
- 如何編寫python模組Python
- Python2、3並存,Python3無法安裝requests模組Python
- 安裝python虛擬環境並配置虛擬環境以及安裝scrapy模組Python
- win10原版ISO映象如何製作安裝光碟_製作win10原版ISO映象安裝光碟圖文詳解Win10
- win10怎麼製作安裝u盤_win10安裝U盤製作教程Win10
- Python 安裝第三方模組的三種方法Python
- 模組的釋出和安裝