jim*_*lan 72 python ubuntu python-2.7
我是Python新手,正在使用Linux机器(Ubuntu 10.10).它正在运行python 2.6,但我想运行2.7因为它有我想要使用的功能.我被敦促不安装2.7并将其设置为我的默认python.
我的问题是,如何安装2.7并与2.6并排运行?
oyl*_*gul 108
我在我的Ubuntu 10.10机器上用pythonbrew做到了.
$ python -V
Python 2.6.6
$ curl -kL https://raw.github.com/utahta/pythonbrew/master/pythonbrew-install | bash
$ . $HOME/.pythonbrew/etc/bashrc
$ pythonbrew install 2.7.1
$ pythonbrew switch 2.7.1
Switched to Python-2.7.1
$ python -V
Python 2.7.1
Run Code Online (Sandbox Code Playgroud)
Fah*_*tha 10
我最近向Python Debian挤压了Python 2.7.由于Ubuntu 10.10比Debian挤压更新,如果你能在挤压时做到这一点,你当然可以在Ubuntu上进行.我无法访问Ubuntu 10.10系统.如果我设置一个,我会测试它,并更新这个答案.所以,这里简要介绍一下我在Debian上所做的事情.
首先,一般而明显的评论,但很容易被忽视.不应该过分重视Debian软件包列出的构建依赖关系.它们可能比需要的更具体.例如,像Python这样设计为可移植并在各种系统上运行的软件不太可能依赖于非常特定的软件版本.运行时依赖性也可以调整,但这应该更加谨慎.但是,运行时依赖性主要是基于此系统上已有的软件动态生成的,因此通常这不是一个大问题.
apt-cache policy python2.7
python2.7:
Installed: 2.7.2-8
Candidate: 2.7.2-8
Version table:
2.7.2-12 0
50 http://debian.csail.mit.edu/debian/ unstable/main i386 Packages
2.7.2-8 0
50 http://debian.csail.mit.edu/debian/ testing/main i386 Packages
*** 2.7.2-8 0
100 /var/lib/dpkg/status
Run Code Online (Sandbox Code Playgroud)
选择我们得到的测试版本
apt-get source python2.7=2.7.2-8
Run Code Online (Sandbox Code Playgroud)
看一下debian/control
,我们看到以下构建依赖关系行.
Build-Depends:debhelper(> = 5),quilt,autoconf,libreadline-dev,libtinfo-dev,libncursesw5-dev(> = 5.3),tk8.5-dev,zlib1g-dev,blt-dev(> = 2.4z ),libssl-dev,libexpat1-dev,sharutils,libbz2-dev,libbluetooth-dev [linux-any],locales [!armel!avr32!hppa!ia64!mipsel],libsqlite3-dev,libffi-dev(> = 3.0) .5),mime-support,libgpm2 [linux-any],netbase,lsb-release,bzip2,libdb4.8-dev,gdb,python,help2man Build-Depends-Indep:python-sphinx Build-Conflicts:tcl8.3 -dev,tk8.3-dev,tcl8.4-dev,tk8.4-dev,python2.7-xml,python-xml,autoconf2.13,libncurses5-dev
挤压时大部分都很容易满足.使用方便的实用程序,apt-show-versions
我们可以使用我的机器
apt-show-versions debhelper quilt autoconf libreadline-dev libtinfo-dev libncursesw5-dev tk8.5-dev zlib1g-dev blt-dev \
libssl-dev libexpat1-dev sharutils libbz2-dev libbluetooth-dev locales libsqlite3-dev \
libffi-dev mime-support libgpm2 netbase lsb-release bzip2 libdb4.8-dev gdb python help2man python-sphinx
autoconf/squeeze uptodate 2.67-2
blt-dev/squeeze uptodate 2.4z-4.2
bzip2/squeeze uptodate 1.0.5-6
debhelper/squeeze-backports uptodate 8.9.13~bpo60+1
gdb/squeeze uptodate 7.0.1-2+b1
help2man/squeeze uptodate 1.38.2
libbluetooth-dev/squeeze uptodate 4.66-3
libbz2-dev/squeeze uptodate 1.0.5-6
libdb4.8-dev/squeeze uptodate 4.8.30-2
libexpat1-dev/squeeze uptodate 2.0.1-7
libffi-dev/squeeze uptodate 3.0.9-3
libgpm2/squeeze uptodate 1.20.4-3.3
libncursesw5-dev/squeeze uptodate 5.7+20100313-5
libreadline-dev/squeeze uptodate 6.1-3
libsqlite3-dev/squeeze uptodate 3.7.3-1
libssl-dev/squeeze uptodate 0.9.8o-4squeeze5
libtinfo-dev not installed
locales/squeeze uptodate 2.11.2-10
lsb-release/squeeze uptodate 3.2-23.2squeeze1
mime-support/squeeze uptodate 3.48-1
netbase/squeeze uptodate 4.45
python/squeeze uptodate 2.6.6-3+squeeze6
python-sphinx/squeeze-backports uptodate 1.0.8+dfsg-2~bpo60+1
quilt/squeeze uptodate 0.48-7
sharutils/squeeze uptodate 1:4.9-1
tk8.5-dev/squeeze uptodate 8.5.8-1
zlib1g-dev/squeeze uptodate 1:1.2.3.4.dfsg-3
Run Code Online (Sandbox Code Playgroud)
我们看到除libtinfo-dev
挤压之外的所有东西都可用.我确实有挤压后退版本debhelper
和python-sphinx
,但这两个版本也可用于满足构建要求的版本中的debian挤压.
另请注意,我已经安装了libncurses5-dev
apt-show-versions libncurses5-dev
libncurses5-dev/squeeze uptodate 5.7+20100313-5
Run Code Online (Sandbox Code Playgroud)
这两个包都对应于源包curses 5.7+20100313-5
.注意libtinfo-dev
事实上取代了libncurses5-dev
.
apt-cache show libtinfo-dev
Package: libtinfo-dev
Source: ncurses
Version: 5.9-4
Installed-Size: 279
Maintainer: Craig Small <csmall@debian.org>
Architecture: i386
Replaces: libncurses5-dev (<< 5.9-3)
Depends: libtinfo5 (= 5.9-4)
Run Code Online (Sandbox Code Playgroud)
人们不希望python 2.7在这样一个特定版本的curses上开发,事实上它并没有.但是,如果您尝试构建包而不满足您获得的依赖关系
debuild -uc -us
dpkg-checkbuilddeps: Unmet build dependencies: libtinfo-dev
dpkg-checkbuilddeps: Build conflicts: libncurses5-dev
debuild: fatal error at line 1289:
You do not appear to have all build dependencies properly met.
You can use mk-build-deps to generate a dummy package which
Depends on all the required packages, or you can install them
manually using dpkg or apt using the error messages just above
this message.
Run Code Online (Sandbox Code Playgroud)
所以,有必要编辑debian/control
.请注意,您还需要类似地编辑文件debian/control.in
,否则control
将无法从中重新生成文件control.in
.做最简单的事情是只是删除libncurses5-dev
从Build-Conflicts
线和libtinfo-dev
从Build-Depends
线,然后再运行debuild -uc -us
一次.如果您要在Debian squeeze上安装此软件包以及标准的默认Python 2.6软件包,您还需要删除这两行
Conflicts: python-profiler (<= 2.7.1-2)
Replaces: python-profiler (<= 2.7.1-2)
Run Code Online (Sandbox Code Playgroud)
这些行是因为2.7包括python-profiler
功能.如果2.7是默认的python,则python-profiler
不再需要.但是,如果安装2.7作为非默认Python,则该推理不适用,并且python-profiler
仍然需要2.6.
这应该成功构建,并导致以下二进制包列表.
ls -lah *.deb
-rw-r--r-- 1 faheem staff 289K Jan 12 02:33 idle-python2.7_2.7.2-8_all.deb
-rw-r--r-- 1 faheem staff 1.1M Jan 12 02:34 libpython2.7_2.7.2-8_i386.deb
-rw-r--r-- 1 faheem staff 2.5M Jan 12 02:34 python2.7_2.7.2-8_i386.deb
-rw-r--r-- 1 faheem staff 12M Jan 12 02:34 python2.7-dbg_2.7.2-8_i386.deb
-rw-r--r-- 1 faheem staff 4.9M Jan 12 02:34 python2.7-dev_2.7.2-8_i386.deb
-rw-r--r-- 1 faheem staff 6.0M Jan 12 02:33 python2.7-doc_2.7.2-8_all.deb
-rw-r--r-- 1 faheem staff 692K Jan 12 02:33 python2.7-examples_2.7.2-8_all.deb
-rw-r--r-- 1 faheem staff 1.7M Jan 12 02:34 python2.7-minimal_2.7.2-8_i386.deb
Run Code Online (Sandbox Code Playgroud)
最后,可以安装二进制包
dpkg -i python2.7-minimal_2.7.2-8_i386.deb python2.7_2.7.2-8_i386.deb python2.7-dev_2.7.2-8_i386.deb libpython2.7_2.7.2-8_i386.deb
Run Code Online (Sandbox Code Playgroud)
dpkg
当它们全部安装时,有时可能会很难满足依赖关系,因此apt-get -f install
如果遇到依赖性错误,可能必须在之后运行,或者在较小的组中安装软件包.
好吧,如果你唯一需要的是argparse(在你的一条评论中看到了!)你可以这么做:
pip install argparse
Run Code Online (Sandbox Code Playgroud)
这不是确切问题的答案:-),但实际上如果你只缺少一些功能,许多2.7功能实际上来自独立项目和/或可以找到一些兼容包,例如:
2.7新奇的列表肯定更长,但大多数其他新功能可能不是一个很大的错过,作为交换,你不要乱丢你的盒子上的多个python安装.否则请使用pythonbrew :-)
小智 1
只需从http://www.python.org/download/releases/2.7.1/下载 Python 2.7并构建它。