I think ... - python3https://blog.kmonsoor.com/2018-07-07T00:00:00+06:00Install latest Python 3 on Linux CentOSĀ 72018-07-07T00:00:00+06:002018-07-07T00:00:00+06:00Khaled Monsoortag:blog.kmonsoor.com,2018-07-07:/install-latest-python3-on-centos-7/<p>Install the latest and greatest Python 3 on CentOS 7 systems</p><h2 id="why">Why<a class="headerlink" href="#why" title="Permanent link">¶</a></h2>
<p>Not all distro created equal. <br>
Some are created to join the space race, some are to hold unto the leagcy, some are cutting-edge, some are cutting edge. Some are born to boot-up IoT devices some are to push out heavy graphics.</p>
<p>That’s the fun (albeit, power) of Linux.</p>
<p><img alt="CentOS 7 logo" class="noZoom" src="https://i.imgur.com/6ZFCdoM.jpg"></p>
<p>CentOS 7 is a powerful and stable distro that runs on thousands (probably, millions) production-grade servers.<br>
In the matter of stability, it’s a beast. However, it doesn’t ship with Python 3, by default. You can install it via <span class="caps">EPEL</span> repository, or the below simple steps.</p>
<p>Also, take a note. The Python <strong>2</strong> comes with the system, which is probably 2.7.5, do <strong><span class="caps">NOT</span></strong> mess with it. Many system components rely on that specific version. If you need the latest versions of 2, use <code>virtualenv</code> or <code>pipenv</code>.</p>
<h3 id="prepare-your-system">Prepare your system<a class="headerlink" href="#prepare-your-system" title="Permanent link">¶</a></h3>
<p>Start with installing pre-requisite utilities for compilation and development support.</p>
<div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span>$ sudo yum update <span class="o">&&</span> sudo yum groupinstall -y <span class="s2">"development tools"</span>
<span class="linenos" data-linenos="2 "></span>$ sudo yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel <span class="se">\</span>
<span class="linenos" data-linenos="3 "></span> sqlite-devel readline-devel tk-devel gdbm-devel <span class="se">\</span>
<span class="linenos" data-linenos="4 "></span> db4-devel libpcap-devel xz-devel expat-devel
</code></pre></div>
<h3 id="download-latest-python-source-code-from-pythonorg">Download latest Python source code from Python.org<a class="headerlink" href="#download-latest-python-source-code-from-pythonorg" title="Permanent link">¶</a></h3>
<div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span>$ wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz
<span class="linenos" data-linenos="2 "></span>$ tar xf Python-3.6.6.tar.xz
<span class="linenos" data-linenos="3 "></span>$ <span class="nb">cd</span> Python-3.6.6
</code></pre></div>
<h3 id="enable-performance-optimizations-optional-but-highly-recommended">Enable performance optimizations (optional, but highly recommended)<a class="headerlink" href="#enable-performance-optimizations-optional-but-highly-recommended" title="Permanent link">¶</a></h3>
<div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span>$ ./configure --prefix<span class="o">=</span>/usr/local --enable-shared <span class="nv">LDFLAGS</span><span class="o">=</span><span class="s2">"-Wl,-rpath /usr/local/lib"</span>
<span class="linenos" data-linenos="2 "></span>$ ./configure --enable-optimizations
</code></pre></div>
<h3 id="build-and-install">Build and install<a class="headerlink" href="#build-and-install" title="Permanent link">¶</a></h3>
<div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span>$ make
<span class="linenos" data-linenos="2 "></span>$ sudo make altinstall
</code></pre></div>
<p>Now, Python 3.6.6 is ready to be used in your system; located in <code>/usr/local/bin/python3.6</code>
<div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span>$ which python3.6
<span class="linenos" data-linenos="2 "></span>/usr/local/bin/python3.6
<span class="linenos" data-linenos="3 "></span>
<span class="linenos" data-linenos="4 "></span>$ python3.6
<span class="linenos" data-linenos="5 "></span>Python <span class="m">3</span>.6.6 <span class="o">(</span>default, Jul <span class="m">10</span> <span class="m">2018</span>, <span class="m">14</span>:04:26<span class="o">)</span>
<span class="linenos" data-linenos="6 "></span><span class="o">[</span>GCC <span class="m">4</span>.8.5 <span class="m">20150623</span> <span class="o">(</span>Red Hat <span class="m">4</span>.8.5-28<span class="o">)]</span> on linux
<span class="linenos" data-linenos="7 "></span>Type <span class="s2">"help"</span>, <span class="s2">"copyright"</span>, <span class="s2">"credits"</span> or <span class="s2">"license"</span> <span class="k">for</span> more information.
<span class="linenos" data-linenos="8 "></span>>>>
</code></pre></div></p>
<p>For convenience, you can create a symbolic-link with a shorter name.
If you had system-installed Python3 (unlikely), <strong>don’t</strong> do this, as some system-components may depend on that specific older version of Python 3.
<div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span>$ sudo ln -s /usr/local/bin/python3.6 /usr/local/bin/python3
<span class="linenos" data-linenos="2 "></span>$ python3
<span class="linenos" data-linenos="3 "></span>Python <span class="m">3</span>.6.6 <span class="o">(</span>default, Jul <span class="m">10</span> <span class="m">2018</span>, <span class="m">14</span>:04:26<span class="o">)</span>
<span class="linenos" data-linenos="4 "></span><span class="o">[</span>GCC <span class="m">4</span>.8.5 <span class="m">20150623</span> <span class="o">(</span>Red Hat <span class="m">4</span>.8.5-28<span class="o">)]</span> on linux
<span class="linenos" data-linenos="5 "></span>Type <span class="s2">"help"</span>, <span class="s2">"copyright"</span>, <span class="s2">"credits"</span> or <span class="s2">"license"</span> <span class="k">for</span> more information.
<span class="linenos" data-linenos="6 "></span>>>>
</code></pre></div></p>
<h2 id="install-wheel-and-pip"><del>Install wheel and pip</del><a class="headerlink" href="#install-wheel-and-pip" title="Permanent link">¶</a></h2>
<p>You don’t need to, because <code>Python 3.6.6</code> includes these necessary tools included.
<div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span>$ pip3.6 -V
<span class="linenos" data-linenos="2 "></span>pip <span class="m">10</span>.0.1 from /usr/local/lib/python3.6/site-packages/pip <span class="o">(</span>python <span class="m">3</span>.6<span class="o">)</span>
<span class="linenos" data-linenos="3 "></span>$ wheel version
<span class="linenos" data-linenos="4 "></span>wheel <span class="m">0</span>.29.0
</code></pre></div></p>