python安裝筆記

ref: python doc - Installing Python Modules (Legacy version)

python setup.py build
python setup.py install

1. build

python setup.py build
the build command is responsible for putting the files to install into a build directory.
change the build dir:
python setup.py build --build-base=/path/to/pybuild/foo-1.0

2. install

python setup.py install
the install command is relatively simple: copy everything under build/lib (or build/lib.plat ) to your chosen installation directory.

2.1 alternate installation

<u>The basic idea is that you supply a base directory for the installation, and the install command picks a set of directories (called an installation scheme) under this base directory in which to install files.</u>

--user
--home
--prefix
--exec-prefix
--install-base
--install-platbase
2.1.1 alternate installation - the user scheme

When don’t have write permission to the global site-packages directory or don’t want to install into it:
python setup.py install --user

Type of file Installation directory
modules userbase/lib/pythonX.Y/site-packages
scripts userbase/bin
data userbase
C headers userbase/include/pythonX.Y/distname
2.1.2 Alternate installation: the home scheme

when you build and maintain a personal stash of Python modules. just like Unix's "home" dir.
e.g. python setup.py install --home=~

Type of file Installation directory
modules home/lib/python
scripts home/bin
data home
C headers home/include/python/distname
2.1.3 Alternate installation: Unix (the prefix scheme)

when you wish to use one <u>Python installation</u> to perform the build/install (i.e., to run the setup script), but install modules into the <u>third-party module directory</u> of a different Python installation (or something that looks like a different Python installation).
e.g. /usr/local/bin/python setup.py install --prefix=/mnt/@server/export

Type of file Installation directory
Python modules prefix/lib/pythonX.Y/site-packages
extension modules exec-prefix/lib/pythonX.Y/site-packages
scripts prefix/bin
data prefix
C headers prefix/include/pythonX.Y/distname

every time you run python setup.py install without any other options, you’re using --prefix and --exec-prefix.

2.2 Custom installation

Type of file Override option
Python modules --install-purelib
extension modules --install-platlib
all modules --install-lib
scripts --install-scripts
data --install-data
C headers --install-headers
python setup.py install --home=~/python \
                        --install-purelib=lib \
                        --install-platlib='lib.$PLAT' \
                        --install-scripts=scripts
                        --install-data=data

or use Distutils config file (see section Distutils Configuration Files):

[install]
install-base=$HOME/python
install-purelib=lib
install-platlib=lib.$PLAT
install-scripts=scripts
install-data=data
2.2.1 Modifying Python’s Search Path

When the Python interpreter executes an import
statement, it searches for both Python code and extension modules along a search path. A default value for the path is configured into the Python binary when the interpreter is built. You can determine the path by importing the sys
module and printing the value of sys.path.

The most convenient way is to add a path configuration file to a directory that’s already on Python’s path, usually to the .../site-packages/ directory. Path configuration files have an extension of .pth, and each line must contain a single path that will be appended to sys.path. (Because the new paths are appended to sys.path, modules in the added directories will not override standard modules. This means you can’t use this mechanism for installing fixed versions of standard modules.)

import sys
sys.path.append('/www/python/')
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市卷要,隨后出現(xiàn)的幾起案子灭衷,更是在濱河造成了極大的恐慌浸须,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,681評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件惫谤,死亡現(xiàn)場離奇詭異汰蓉,居然都是意外死亡,警方通過查閱死者的電腦和手機傻昙,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,205評論 3 399
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來彩扔,“玉大人,你說我怎么就攤上這事僻爽〕娴铮” “怎么了?”我有些...
    開封第一講書人閱讀 169,421評論 0 362
  • 文/不壞的土叔 我叫張陵胸梆,是天一觀的道長敦捧。 經(jīng)常有香客問我,道長碰镜,這世上最難降的妖魔是什么兢卵? 我笑而不...
    開封第一講書人閱讀 60,114評論 1 300
  • 正文 為了忘掉前任,我火速辦了婚禮绪颖,結(jié)果婚禮上秽荤,老公的妹妹穿的比我還像新娘。我一直安慰自己柠横,他們只是感情好窃款,可當(dāng)我...
    茶點故事閱讀 69,116評論 6 398
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著牍氛,像睡著了一般晨继。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上搬俊,一...
    開封第一講書人閱讀 52,713評論 1 312
  • 那天紊扬,我揣著相機與錄音,去河邊找鬼唉擂。 笑死餐屎,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的玩祟。 我是一名探鬼主播啤挎,決...
    沈念sama閱讀 41,170評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了庆聘?” 一聲冷哼從身側(cè)響起胜臊,我...
    開封第一講書人閱讀 40,116評論 0 277
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎伙判,沒想到半個月后象对,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,651評論 1 320
  • 正文 獨居荒郊野嶺守林人離奇死亡宴抚,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,714評論 3 342
  • 正文 我和宋清朗相戀三年勒魔,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片菇曲。...
    茶點故事閱讀 40,865評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡冠绢,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出常潮,到底是詐尸還是另有隱情弟胀,我是刑警寧澤,帶...
    沈念sama閱讀 36,527評論 5 351
  • 正文 年R本政府宣布喊式,位于F島的核電站孵户,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏岔留。R本人自食惡果不足惜夏哭,卻給世界環(huán)境...
    茶點故事閱讀 42,211評論 3 336
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望献联。 院中可真熱鬧竖配,春花似錦、人聲如沸里逆。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,699評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽运悲。三九已至龄减,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間班眯,已是汗流浹背希停。 一陣腳步聲響...
    開封第一講書人閱讀 33,814評論 1 274
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留署隘,地道東北人宠能。 一個月前我還...
    沈念sama閱讀 49,299評論 3 379
  • 正文 我出身青樓,卻偏偏與公主長得像磁餐,于是被迫代替她去往敵國和親违崇。 傳聞我的和親對象是個殘疾皇子阿弃,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,870評論 2 361

推薦閱讀更多精彩內(nèi)容