Debian python 2 and 3

How can I switch between Python 2.7 and 3.4 that are installed on Debian 8 (Jessie)?

I’m using Debian 8.2 (Jessie), and have both Python 2.7 and 3.4 installed. Python 2.7 is the default and that’s what is used when I run a Python script or interactively in the Terminal. How can I switch between the two Python versions? I would like to start working in Python 3.4, and still be able to revert to 2.7.

2 Answers 2

Why not use #! /usr/bin/python2.7 when you want to use python 2.7 and #! /usr/bin/python3.4 when you want to use python 3.4?

Alternatively if you want your python programs to automatically use the latest python 2.x or python 3.x, use #!/usr/bin/python2 or #!/usr/bin/python3 — they are symlinks pointing to the latest versions, 2.7 and 3.4 respectively at the moment.

BTW, I have the following python interpreters installed on my debian sid system at the moment. They all work as expected.

lrwxrwxrwx 1 root root 9 Mar 17 2015 /usr/bin/python -> python2.7* lrwxrwxrwx 1 root root 9 Mar 17 2015 /usr/bin/python2 -> python2.7* -rwxr-xr-x 1 root root 2652824 May 9 2013 /usr/bin/python2.6* -rwxr-xr-x 1 root root 3500648 Sep 14 11:04 /usr/bin/python2.7* lrwxrwxrwx 1 root root 9 Jun 28 09:42 /usr/bin/python3 -> python3.4* -rwxr-xr-x 1 root root 2965608 Nov 28 2010 /usr/bin/python3.1* lrwxrwxrwx 1 root root 11 May 9 2013 /usr/bin/python3.2 -> python3.2mu* -rwxr-xr-x 1 root root 2890040 May 9 2013 /usr/bin/python3.2mu* -rwxr-xr-x 2 root root 4148216 Sep 24 11:22 /usr/bin/python3.4* -rwxr-xr-x 2 root root 4148216 Sep 24 11:22 /usr/bin/python3.4m* lrwxrwxrwx 1 root root 10 Jun 28 09:42 /usr/bin/python3m -> python3.4m* 

Источник

Debian python 2 and 3

Introduction

Python, the high-level, interactive object oriented language, includes an extensive class library with lots of goodies for network programming, system administration, sounds and graphics. Debian provides the latest stable Python 3 release; it also provides the latest stable Python 2 release, but Python 2 is unsupported by the Python Foundation since 2020-01-01 and is being removed as of Debian 11 (Bullseye). It may also provide additional versions, as well as tons of third party packages. Python is an important part of the Debian ecosystem.

Python is very easy to learn. You can begin with the DebianWomen/PythonTutorial or the official online tutorial if you want to get started programming in Python. You might also be interested in the Python wiki, the Python FAQ, and the online documentation.

Software written in the Python programming language is executed by the Python interpreter. It is usually compiled into platform-independent bytecode files to increase performance. Python compiles and writes bytecode *.pyc files alongside the *.py sources. Extension modules can also be written in C, which are distributed as .so shared libraries.

Читайте также:  Проверка существования таблицы sql php

Therefore, software written in pure Python can be distributed as source code or as compiled bytecode. The latter is similar to Java.

Python in Debian

Sources available: ssh://git.debian.org//git/git/python-modules/misc/python-debian-artwork.git

As such, with hundreds of Python modules and multiple versions of Python supported, Debian is the largest «integrated Python distribution». Users of other operating systems (e.g. Windows and OS X) can also benefit from this integrative effort by means of virtualization (e.g. see NeuroDebian VM page for easy way to start)

Please also refer to the packaging style guide and Python Packaging wiki pages.

As of 2015-10-09 we now maintain all of our packages in Git. Here is team policy for using git for team packages.

NOTE: Debian 11 (bullseye) has removed the «python» package and the ‘/usr/bin/python’ symlink due to the deprecation of Python 2. No packaged scripts should depend on the existence of ‘/usr/bin/python’: if they do, that is a bug that should be reported to Debian. You can use the ‘python-is-python3’ or ‘python-is-python2’ packages to restore an appropriate ‘/usr/bin/python’ symlink for third-party or legacy scripts. See also Python/FAQ#Python_2_support.

Maintainers

  • cpython-team maintains the Python compiler/interpreter package.
  • Debian Python Team maintains some Python modules and applications.

Supported Python Versions

  • Debian Bookworm currently contains 3.11, and will likely not ship Python 2, see also Python/FAQ#Python_2_support.
  • Debian Bullseye contains 3.9, minimal support for 2.7
  • Debian Buster contains Python 2.7, 3.7
  • Debian Stretch contains Python 2.7, 3.5
  • Debian Jessie contains Python 2.7, 3.4
  • Debian Wheezy contains Python 2.7, 3.2
  • Debian Squeeze contains Python 2.5, 2.6 (the default), 3.1.
  • Debian Lenny contains Python 2.4 and 2.5 (the default).
  • Debian Testing contains some 2.x and 3.x
  • Debian Unstable contains some 2.x and 3.x, python2 is being removed https://wiki.debian.org/Python/2Removal
  • Debian experimental may also contain some (experimental!) packages 2.x and 3.x
  • Distribution(s) shipping python3.11
  • Distribution(s) shipping python3.10
  • Distribution(s) shipping python3.9
  • Distribution(s) shipping python3.8 (none)
  • Distribution(s) shipping python3.7
  • Distribution(s) shipping python3.6 (none)
  • Distribution(s) shipping python3.5
  • Distribution(s) shipping python3.4
  • Distribution(s) shipping python3.3
  • Distribution(s) shipping python3.2
  • Distribution(s) shipping python3.1
  • Distribution(s) shipping python3.0 (none)
  • Distribution(s) shipping python2.7
  • Distribution(s) shipping python2.6
  • Distribution(s) shipping python2.5 (none)
  • Distribution(s) shipping python2.4 (none)

Debian Python Policy for Python developers

The Debian Python Policy describes conventions for packaging and distributing Python code in Debian.

Feel free to ask any questions on debian-python@lists.debian.org mailing list.

If you want to maintain a Python package, you have to know how the Debian Development works.

Deviations from upstream

  • dist-packages instead of site-packages. Third party Python software installed from Debian packages goes into dist-packages, not site-packages. This is to reduce conflict between the system Python, and any from-source Python build you might install manually.
  • The standard profile and pstats modules are not included, due to restrictive redistribution clauses in their license that don’t meet the DFSG. cProfile and hotshot are however included.
  • In Debian 7 (Wheezy), the python-setuptools package installs the Distribute fork instead of the standard setuptools. In Debian 8 (Jessie), we reverted back to the merged setuptools project.
  • Also in Debian 7 (Wheezy), the python-virtualenv also uses distribute by default, but can enable classic setuptools with an optional switch. As above, in Debian 8 (Jessie) this just use the merged setuptools.
  • distutils setup scripts install files in /usr/local/ not sys.prefix (which is normally /usr/). This is because /usr/ is reserved for files installed from Debian packages. Note that /usr/local/lib/pythonX.Y/dist-packages is in sys.path so that modules not installed from Debian packages can still be accessed by the system Python. Tools like debhelper pass the --install-layout=deb option to the setup script while building a Debian package so that its installs files into /usr/ not /usr/local/.
  • Python 2.7, 3.3, and 3.4 are multiarch aware.
Читайте также:  Python красивый вывод на консоль

Encouraged practices

  • Style guide for packaging Python libraries (includes adding Python 3 support)
  • Style guide for packaging Python applications (includes Python 3 support)
  • There is a growing number of python-*-dbg packages for modules with extensions. They provide extensions built using python*-dbg libraries allowing to take advantage of GDB constantly improving support for debugging of Python modules and extensions. If you build extensions module, please provide corresponding -dbg package
  • Converting your package to dh_python2

Installing from Source

If you want the latest version, or a development version of Python, you will likely need to install it from source. In order to do that, first make sure you have build dependencies. As root, run: «aptitude build-dep python3»

Pick your version and download the «Gzipped source tarball» of the version of your choice from Python download page. Once you have the archive, extract it using «tar -xvf Python-.tgz». Once that is done, go to that directory with «cd Python-» and use the following command to compile Python from source: «./configure && make && make test» (as regular user). To install it globally without damaging system Python installed with APT, use the altinstall target (as root): «make altinstall».

See also

Источник

How to Switch Python Version in Ubuntu & Debian

Python is a high-level programming language, widely used for system programming. It is available for all popular operating systems. You can install more than one Python version on a single system. Once you have installed multiple Python versions, you can switch the default Python with the update-alternatives tool.

All the Python developers are recommended to use a virtual environment for the applications. Which provides an isolated environment for the application with a defined Python version.

Читайте также:  Название страницы

Switch Python Version on Ubuntu & Debian

The update-alternatives command-line tool is to create and maintain symbolic links for the default commands. With the help of this, we can easily switch commands to different versions. For, this tutorial, Python 3.10, and Python 2.7 are pre-installed on a Debian system. We will create a group for both commands and set symbolic links.

    Create a symlink from /usr/bin/python2.7 to /usr/bin/python and set the group name as “python”. Later, group name will be used to switch links.

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 
Output
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 2 
Output
update-alternatives: using /usr/bin/python3.10 to provide /usr/bin/python (python) in auto mode
sudo update-alternatives --config python 
Output: [Select on option]
There are 2 choices for the alternative python (providing /usr/bin/python). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/bin/python3.10 2 auto mode * 1 /usr/bin/python2.7 1 manual mode 2 /usr/bin/python3.10 2 manual mode Press to keep the current choice[*], or type selection number:

Conclusion

In this tutorial, you have learned about switching the default Python versions on your Ubuntu and Debian Linux systems. Instead of switching version you can also configure Python virtual environment for your applications.

Источник

Install Python 3.x or 2.7 on Debian 11 Bullseye Linux

Python is a free, open-source programming language for a wide range of software projects. This programming language comes with clear syntax and good readability. It is considered easy to learn and can be interpreted in common operating systems.

Also, Python offers good scalability and can be used for complex software projects. Due to the expressive, minimalist syntax, applications can be implemented with just a few lines of code and less susceptibility to programming errors. To ensure simplicity and clarity, Python gets along with very few keywords and uses indentations as structuring elements.

The platform-independent programming language Python runs on Windows, Linux/Unix, Mac OS X, and more… There are also integrations into the virtual machines of Java and. NET.

The Python programming language offers a number of advantages. The most important advantages are briefly summarized below:

  • simple syntax
  • easy to learn due to the small number of keywords and the clear structure
  • no variable declaration is necessary
  • little prone to errors
  • fewer lines of code compared to many other programming languages
  • easy to read and maintain code
  • Support of various programming paradigms
  • good extensibility thanks to a large collection of Python add-on packages
  • good scalability
  • extensive standard library available
  • suitable for complex tasks and almost all application problems
  • usable for the common operating systems
  • freely available

Источник

Оцените статью