"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Manage Multiple Python Versions on a Linux System?

How to Manage Multiple Python Versions on a Linux System?

Published on 2024-11-09
Browse:861

How to Manage Multiple Python Versions on a Linux System?

Installing Multiple Python Versions on Linux: Official Documentation and Recommendations

Question: Is there any official Python website documentation that describes how to install and execute multiple Python versions on a single Linux machine?

Answer: There is no official documentation on this topic available on the Python website. The recommendation is to rely on the operating system-specific guidelines for handling multiple Python versions.

For example, on Linux systems, you can simply install multiple Python versions without any conflicts, as each installation maintains its own libraries in dedicated directories. You can then use commands such as /usr/bin/python2.5 or /usr/bin/python2.6 to specify the desired Python version for execution. To set a default Python version, create a symbolic link from /usr/bin/python to the preferred version, such as:

ln -s /usr/bin/python2.6 /usr/bin/python

Compiling and Installing Manually:

If you prefer to compile and install Python versions manually, you can refer to the guidelines outlined in the Python source code's readme file:

  • If you intend to install multiple versions under the same installation prefix (--prefix argument in the configure script), ensure that your main Python executable is not overwritten by another version's installation.
  • All installations created using make altinstall include the major and minor version in their naming, allowing them to coexist alongside each other.
  • make install creates a symbolic link named ${prefix}/bin/python3 that points to ${prefix}/bin/pythonX.Y.
  • To install multiple versions under the same prefix, select one as the primary version and install it using make install. Install the other versions using make altinstall.

For example, if you want to install Python versions 2.5, 2.6, and 3.0 with 2.6 designated as the primary version, you would execute these commands:

  • In the build directory for 2.6: make install
  • In the build directories for the other versions: make altinstall
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3