1. 程式人生 > >suse下無root使用者安裝python 2.7

suse下無root使用者安裝python 2.7

在生產環境的機器上(作業系統為suse),想要使用python做一些工作,隨系統安裝的python版本為2.6,且相應的包也不全,編譯cx_ORACLE時報錯,“無法找到Python.h”,想想還是自己再安裝一個開發版本的吧。

說幹就幹,等等,有沒有root使用者?問了一下infra組,由於主機已經交維,root使用者許可權被收回,無奈只能使用應用的使用者來嘗試安裝,首先下載Python 2 系列最新的版本2.7.13原始碼包,下載地址為:

檔案下載後,在使用者的目錄下解壓,在編譯之前先執行下configure –help看看:

`configure' configures python 2.7 to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
--help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print `checking ...' messages --cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for `--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or `..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, `make install' will install all the files in `/usr/local/bin', `/usr/local/lib' etc. You can specify an installation prefix other than `/usr/local' using `--prefix', for instance `--prefix=$HOME'.

上面只是截取了一部分內容,看重點,“預設情況下,make install會把所有的檔案安裝到/usr/local/bin和/usr/local/lib等目錄,但可以使用–prefix指定安裝目錄“,好了,要的就是這個。依次執行如下命令:

./configure --prefix=/users/freeware/python2.7
make install

執行過程一切順利,在prefix指定的目錄下安裝了四個目錄:

bin  include  lib  share

進入include查詢Python.h,果然在,這下應該沒有問題了吧,在系統profile檔案中把python2.7的bin目錄設定到PATH中,這樣系統就不會找預設的python命令了。

執行了下python命令,提示版本是2.7.13,但又出現了意想不到的事情:

import readline
ImportError: No module named readline

在解壓目錄下執行

python setup.py install

安裝後,執行python,一切OK。