About
This page shows you how to install python next to the actual python system version.
Python is generally controlled/distributed with the Linux distribution. Upgrading it may cause several defect in your system.
A better way is to install an other Python installation next to the actual.
The installation is done via the autoconf process
Articles Related
Steps
Fortunately, the configuration and build process has been automated for Unix and Linux installations, so all you usually have to do is type a few commands and sit back.
Get it
Download it,unzip it
wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
tar -xvzf Python-2.7.13.tgz
Installation Documentation
The whole installation documentation can be found in the README file. Check the Build instructions section.
Prerequisites
To build the sqlite3 module, you'll need the sqlite3 or libsqlite3 packages installed, including the header files.
Many modern operating systems distribute the headers in a separate package to the library - often it will be the same name as the main package, but with a -dev or -devel suffix.
Configuration
Before you can build Python, you must first configure it. The configuration will determine your system configuration and creates the Makefile. (ie all build parameters)
./configure
Some special cases are handled by passing options (argument) to the configure script. See the README section Configuration options and variables
Below are a couple of options:
- –prefix (default /usr/local). Location of all platform-independent files in subdirectories
- –exec-prefix (defaults to the –prefix directory). Location of all binary and other platform-specific files will be installed in subdirectories
- –enable-optimizations Sets the default make targets up to enable Profile Guided Optimization (PGO) and may be used to auto-enable Link Time Optimization (LTO) on some platforms.
When it's done, you are ready to run make.
Make (build)
In the toplevel directory
make
The interpreter executable python is built in the top level directory.
Almost all modules are automatically built as appropriate under guidance of the setup.py script, which is run by Make after the interpreter has been built.
Test
Testing the interpreter, in the top-level directory.
make test
This runs the test set twice (once with no compiled files, once with the compiled files left by the previous test run).
The test set produces some output. You can generally ignore the messages about skipped tests due to optional features which can't be imported. If a message is printed about a failed test or a traceback or core dump is produced, something is wrong.
output Example:
355 tests OK.
2 tests failed:
test_gdb test_sqlite
1 test altered the execution environment:
test_import
43 tests skipped:
test_aepack test_al test_applesingle test_bsddb185 test_bsddb3
test_bz2 test_cd test_cl test_codecmaps_cn test_codecmaps_hk
test_codecmaps_jp test_codecmaps_kr test_codecmaps_tw test_curses
test_dl test_gdbm test_gl test_idle test_imageop test_imgfile
test_kqueue test_linuxaudiodev test_macos test_macostools
test_msilib test_ossaudiodev test_readline test_scriptpackages
test_smtpnet test_socketserver test_startfile test_sunaudiodev
test_tcl test_timeout test_tk test_ttk_guionly test_ttk_textonly
test_turtle test_urllib2net test_urllibnet test_winreg
test_winsound test_zipfile64
9 skips unexpected on linux2:
test_bz2 test_gdbm test_idle test_readline test_tcl test_tk
test_ttk_guionly test_ttk_textonly test_turtle
make: *** [test] Error 1
Install
Installation of the Python binary, library modules, shared library modules, include files, configuration files, and the manual page.
If DESTDIR is set, it will be taken as the root directory of the installation, and files will be installed into $(DESTDIR)$(prefix), $(DESTDIR)$(exec_prefix), etc.
To install Python not as the primary installation, run make altinstall
make altinstall
All files and directories installed using “make altinstall” contain the major and minor version and can thus live side-by-side even with the same prefix altinstall skips creating the python link and the manual pages links
With altinstall: All subdirectories created will have Python's version number in their name, e.g. the library modules are installed in /usr/local/lib/python
/ by default, where is the
.release number (e.g. “2.1”).
The only file not installed with a version number in its
name is the manual page, installed as “/usr/local/man/man1/python.1”
by default.
You generally don't want to do that. This is for informational purpose.
To install the primary version
make install
install will hide the system binaries and manual pages
For example, if you want to install Python 2.5, 2.6 and 3.0 with 2.6 being
the primary version, you would execute “make install” in your 2.6 build
directory and “make altinstall” in the others.
Check
The Python binary is installed as “python
”
/usr/local/bin/python2.7
Python 2.7.13 (default, May 8 2017, 12:29:27)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>