Programing

Ubuntu의 Python 2.7

lottogame 2020. 10. 27. 07:46
반응형

Ubuntu의 Python 2.7


저는 Python을 처음 사용하며 Linux 컴퓨터 (Ubuntu 10.10)에서 작업하고 있습니다. 파이썬 2.6을 실행 중이지만 사용하고 싶은 기능이 있으므로 2.7을 실행하고 싶습니다. 2.7을 설치하지 않고 기본 파이썬으로 설정하라는 권고를 받았습니다.

내 질문은 2.7을 어떻게 설치하고 2.6과 나란히 실행할 수 있습니까?


내 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

또한 Python 3.2를 설치하는 데 사용했습니다 .


저는 최근에 Python 2.7을 Debian squeeze로 백 포트했습니다. Ubuntu 10.10은 Debian squeeze보다 최신 버전이므로 squeeze에서 할 수 있다면 Ubuntu에서 확실히 할 수 있습니다. Ubuntu 10.10 시스템에 액세스 할 수 없습니다. 하나를 설정하면 테스트하고이 답변을 업데이트합니다. 그래서 여기에 제가 데비안에서 한 일에 대한 간단한 스케치가 있습니다.

첫째, 일반적이고 명백한 주석이지만 쉽게 간과되는 것입니다. 데비안 패키지의 나열된 빌드 종속성을 너무 심각하게 생각해서는 안됩니다. 필요한 것보다 훨씬 더 구체적 일 수 있습니다. 예를 들어, 이식 가능하고 다양한 시스템에서 실행되도록 설계된 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

우리가 얻는 테스트 버전 선택

apt-get source python2.7=2.7.2-8

를 보면 debian/control다음과 같은 빌드 종속성 줄이 있습니다.

빌드에 따라 다름 : 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], 로케일 [! 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

libtinfo-dev스퀴즈를 제외한 모든 것이 가능 하다는 것을 알 수 있습니다. debhelper의 스퀴즈 백 포트 버전이 python-sphinx있지만이 두 가지 모두 빌드 요구 사항을 충족하는 버전의 데비안 스퀴즈에도 사용할 수 있습니다.

libncurses5-dev가 설치되어 있는지도 관찰하십시오.

apt-show-versions libncurses5-dev

libncurses5-dev/squeeze uptodate 5.7+20100313-5

이 두 패키지 모두 소스 패키지에 해당합니다 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)

누군가는 파이썬 2.7이 그러한 특정 버전의 저주에서 개발 될 것이라고 기대하지 않을 것이며, 사실 그렇지 않습니다. 그러나 종속성을 충족시키지 않고 패키지를 빌드하려고하면

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.

So, it is necessary to edit debian/control. Note that you also need to similarly edit the file debian/control.in, otherwise the control file will be incorrectly regenerated from control.in. The simplest thing to do is just remove libncurses5-dev from the Build-Conflicts line and libtinfo-dev from the Build-Depends line, and then run debuild -uc -us again. If you are going to have this package installed alongside the standard default Python 2.6 packages on Debian squeeze, you also need to remove the two lines

Conflicts: python-profiler (<= 2.7.1-2)
Replaces: python-profiler (<= 2.7.1-2)

Those lines are there because 2.7 includes the python-profiler functionality. If 2.7 is the default python, then python-profiler is no longer necessary. However, if one is installing 2.7 as a non-default Python, that reasoning does not apply, and python-profiler is still needed by 2.6.

This should build successfully, and result in the following list of binary packages.

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

Finally, one can install the binary packages with

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 

Sometimes dpkg can be a little difficult about satisfying dependencies when they are all installed at once, so you might have to run apt-get -f install afterwards if you get dependency errors, or alternatively install the packages in smaller groups.


Well if the only thing you need is argparse (saw that in one of your comments!) you could just do :

pip install argparse

This is not exactly an answer to the exact question :-) , but indeed if you are only missing a few feature, many 2.7 features actually come from independent projects and/or some compatibility packages can be found, eg:

The list of 2.7 novelties is admittedly longer, but most of the other new features are probably not a big miss, and in exchange you do not mess around with multiple python installations on your box. Otherwise go with pythonbrew :-)


ubuntu 12.04

Install dependencies:

$ sudo apt-get install python-software-properties

Add the repo:

$ sudo add-apt-repository ppa:fkrull/deadsnakes

Update the repo index:

$ sudo apt-get update

Install Python 3.3:

$ sudo apt-get install python3.3

ubuntu 12.04 > more

Installing the dependencies:

$ sudo apt-get install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev

Download and compile python:

$ wget http://python.org/ftp/python/3.3.0/Python-3.3.0.tar.bz2

$ tar jxf ./Python-3.3.0.tar.bz2

$ cd ./Python-3.3.0

$ ./configure --prefix=/opt/python3.3

$ make && sudo make install

Some nice touches to install a py command by creating a symlink:

$ mkdir ~/bin
$ ln -s /opt/python3.3/bin/python ~/bin/py

Just download Python 2.7 from http://www.python.org/download/releases/2.7.1/ and build it.


You can use virtualenv to create distinct Python environments. Just being newsy, but what does Python 2.7 have that you need?


Another option is to install ActivePython if you do not want to compile things yourself. It includes a binary package manager as well.

참고URL : https://stackoverflow.com/questions/5233536/python-2-7-on-ubuntu

반응형