您的位置:首页 > 编程语言 > Python开发

Debian 7 安装 Python3.4

2014-08-11 22:09 453 查看
Debian 7 自带的python是2.7.3,要用最新的3.4版本怎么办?我们从官网下载压缩包自己编译。

一、安装编译用的包

$ sudo apt-get install build-essential
$ sudo apt-get install libncurses5-dev libncursesw5-dev libreadline6-dev
$ sudo apt-get install libdb5.1-dev libgdbm-dev libsqlite3-dev libssl-dev
$ sudo apt-get install libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev


二、下载压缩包

wget -c https://www.python.org/ftp/python/3.4.1/Python-3.4.1.tgz[/code] 
三、编译安装

$ cd download/
$ tar -zxf Python-3.4.1.tgz
$ cd Python-3.4.1
$ ./configure --prefix=/opt/python-3.4.1
$ make
$ sudo make install
$ cd download/
$ sudo rm -rf Python-3.4.1 #删除解压目录


安装好后把 python3 添加到PATH里,打开
~/.bashrc 文件,在最后添加:


export PATH=$PATH:/opt/python-3.4.1/bin


保存后:

source .bashrc


在终端里输入 python3,可以看到现在的版本是3.4.1。

$ python3
Python 3.4.1 (default, Aug 11 2014, 01:23:53)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>


2015.01.09 更新:

在make时出现这个提示:

# Substitution happens here, as the completely-expanded BINDIR
# is not available in configure
sed -e "s,@EXENAME@,/opt/python-3.4.2/bin/python3.4m," < ./Misc/python-config.in >python-config.py
# Replace makefile compat. variable references with shell script compat. ones; ->
sed -e 's,\$(\([A-Za-z0-9_]*\)),\$\{\1\},g' < Misc/python-config.sh >python-config
# On Darwin, always use the python version of the script, the shell
# version doesn't use the compiler customizations that are provided
# in python (_osx_support.py).
if test `uname -s` = Darwin; then \
cp python-config.py python-config; \
fi


按提示操作:

$ sed -e "s,@EXENAME@,/opt/python-3.4.2/bin/python3.4m," < ./Misc/python-config.in >python-config.py
$ sed -e 's,\$(\([A-Za-z0-9_]*\)),\$\{\1\},g' < Misc/python-config.sh >python-config


再make:

$ make


最后:

sudo make install


在编译安装python3.4.2时有这个提示:

INFO: Can't locate Tcl/Tk libs and/or headers

Python build finished successfully!
The necessary bits to build these optional modules were not found:
_tkinter
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


解决办法:

sudo apt-get install python-tk tcl tk tcl-dev tk-dev


--End--
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: