1.首先,从sohu的镜像服务器上下载Python3.5的最新的源文件:
wget http://mirrors.sohu.com/python/3.5.1/Python-3.5.1.tgz
2.解压
tar -xzvf Python-3.5.1.tgz
3.接下来就可以编译安装了,我想安装在自己指定的目录下,避免跟系统自带的Python2.6冲突。
进入解压后的Python-3.5.1
目录,首先查看README
文件,前面的介绍:
Build Instructions
------------------
On Unix, Linux, BSD, OSX, and Cygwin:
./configure
make
make test
sudo make install
This will install Python as python3.
You can pass many options to the configure script; run "./configure --help" to
find out more. On OSX and Cygwin, the executable is called python.exe;
elsewhere it's just python.
根据提示,执行./configure --help
查看帮助:
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'.
根据提示,在./configure
后面加上--prefix=$HOME
应该就可以了。
4.完整的命令如下
./configure --prefix=/home/python3
make
make install
5.安装完检查一下python3目录:
[python3]$ ls
bin include lib share
6.把python3/bin
目录加到用户的PATH变量中。
7.测试一下:
[bin]$ python3
Python 3.5.1 (default, Jan 17 2016, 22:57:35)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()