在生产环境的机器上(操作系统为suse),想要使用python做一些工作,随系统安装的python版本为2.6,且相应的包也不全,编译cx_ORACLE时报错,“无法找到Python.h”,想想还是自己再安装一个开发版本的吧。
说干就干,等等,有没有root用户?问了一下infra组,由于主机已经交维,root用户权限被收回,无奈只能使用应用的用户来尝试安装,首先下载Python 2 系列最新的版本2.7.13源码包,下载地址为:
https://www.python.org/downloads/release/python-2713/
文件下载后,在用户的目录下解压,在编译之前先执行下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
缺少readline包,那就安装吧,主机没有联网,只能下载离线包,下载地址为:
https://pypi.python.org/pypi/readline/
在解压目录下执行
python setup.py install
安装后,执行python,一切OK。