<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dennis Ping</title>
    <description>The latest articles on DEV Community by Dennis Ping (@dennisping).</description>
    <link>https://dev.to/dennisping</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F747401%2Fe3c98f20-90ca-4077-9d64-094f43a8dc1c.jpeg</url>
      <title>DEV Community: Dennis Ping</title>
      <link>https://dev.to/dennisping</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dennisping"/>
    <language>en</language>
    <item>
      <title>How to install any version of Python on Northeastern's Linux server</title>
      <dc:creator>Dennis Ping</dc:creator>
      <pubDate>Wed, 20 Jul 2022 03:42:47 +0000</pubDate>
      <link>https://dev.to/dennisping/how-to-install-any-version-of-python-on-northeasterns-linux-server-5fjp</link>
      <guid>https://dev.to/dennisping/how-to-install-any-version-of-python-on-northeasterns-linux-server-5fjp</guid>
      <description>&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Northeastern's Khoury Linux server is locked to old Python 3.6.8. In addition, you aren't allowed to install any Pip packages such as numpy, pandas, matplotlib, or scikit-learn! 😥&lt;/p&gt;

&lt;h2&gt;
  
  
  Goal
&lt;/h2&gt;

&lt;p&gt;Today I'll show you how to install ANY Python version and ANY Pip packages on your personal account in the Khoury Linux server! I'll use Python 3.10.5 (the latest version at time of writing).&lt;/p&gt;

&lt;h2&gt;
  
  
  I don't care. Just give me the script!
&lt;/h2&gt;

&lt;p&gt;Copy paste this entire code block into your terminal after logging into the Linux server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget https://github.com/indygreg/python-build-standalone/releases/download/20220630/cpython-3.10.5+20220630-x86_64_v3-unknown-linux-gnu-install_only.tar.gz -O - | tar -xz &amp;amp;&amp;amp; mv python PortablePython
python3 -venv ~/temp_venv
source ~/temp_venv/bin/activate
python3 -m pip install virtualenv
virtualenv -p=~/PortablePython/bin/python3.10 ~/Python3.10
deactivate
rm -r ~/temp_venv
if [ ! -e .bash_profile ]; then touch .bash_profile; fi;
echo alias activate="cd ~; source Python3.10/bin/activate &amp;gt;&amp;gt; .bash_profile
source .bash_profile
activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Steps and explanations below:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Login to your Northeastern Khoury account
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh &amp;lt;username&amp;gt;@login.khoury.northeastern.edu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify Python3 version&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see &lt;code&gt;python 3.6.8&lt;/code&gt; which is Northeastern's default Python.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Download your desired Python version
&lt;/h2&gt;

&lt;p&gt;Since we are blocked from installing a fresh version of Python, we need to use a prebuilt portable version.  Luckily, &lt;a href="https://github.com/indygreg/python-build-standalone/releases"&gt;someone on Github&lt;/a&gt; has already prebuilt the binaries for Windows, Mac, and Linux.&lt;/p&gt;

&lt;p&gt;We are looking for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python 3.10.5&lt;/li&gt;
&lt;li&gt;Targeting Linux GNU&lt;/li&gt;
&lt;li&gt;x86_64 bit v3 (for Intel Haswell 2013 and above)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget https://github.com/indygreg/python-build-standalone/releases/download/20220630/cpython-3.10.5+20220630-x86_64_v3-unknown-linux-gnu-install_only.tar.gz -O - | tar -xz &amp;amp;&amp;amp; mv python PortablePython
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running this &lt;code&gt;wget&lt;/code&gt; command, type &lt;code&gt;ls&lt;/code&gt; and you should see a new directory called &lt;code&gt;PortablePython&lt;/code&gt;. Keep this! We will point our Linux machine to use this version instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Create virtual environment #1
&lt;/h2&gt;

&lt;p&gt;Create a temporary virtual environment called &lt;code&gt;temp_venv&lt;/code&gt; in your home directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 -venv ~/temp_venv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Activate this &lt;code&gt;temp_venv&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source ~/temp_venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install &lt;code&gt;virtualenv&lt;/code&gt; 3rd party package into this &lt;code&gt;temp_venv&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 -m pip install virtualenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why do this? The default &lt;code&gt;venv&lt;/code&gt; only lets us create a virtual environment of our current Python version, while the &lt;code&gt;virtualenv&lt;/code&gt; package lets us create a virtual environment of ANY Python version (older or newer).&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Create virtual environment #2
&lt;/h2&gt;

&lt;p&gt;Create a permanent virtual environment called &lt;code&gt;Python3.10&lt;/code&gt; (or whatever you like). I recommend a short, descriptive name. Create it in your HOME directory for simplicity sake.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;virtualenv -p=~/PortablePython/bin/python3.10 ~/Python3.10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Deactivate and delete &lt;code&gt;temp_venv&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;deactivate
rm -r ~/temp_venv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create an alias command so we can point our Linux machine to use Python3.10&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if [ ! -e .bash_profile ]; then touch .bash_profile; fi;
echo alias activate="cd ~; source Python3.10/bin/activate &amp;gt;&amp;gt; .bash_profile
source .bash_profile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Freedom!
&lt;/h2&gt;

&lt;p&gt;Activate and deactivate your Python 3.10.5 virtual environment with these 2 commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;activate
deactivate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see a new label in your terminal prompt whenever activated&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(python3.10) -bash-4.2$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify that it's indeed the correct version (3.10.5)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install anything you want!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 -m pip install numpy pandas matplotlib scikit-learn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check your installed pip packages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 -m pip list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Notes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Every time you log in, you have to run &lt;code&gt;activate&lt;/code&gt; in order to use your own Python virtual env.&lt;/li&gt;
&lt;li&gt;You don't have to &lt;code&gt;deactivate&lt;/code&gt; before logging out. It will automatically do it for you.&lt;/li&gt;
&lt;li&gt;Don't worry, nothing is actually being overwritten on your Khoury Linux account, you're just pointing it to use your virtual env &lt;code&gt;Python3.10&lt;/code&gt; instead.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>northeastern</category>
      <category>khoury</category>
      <category>linux</category>
      <category>python</category>
    </item>
  </channel>
</rss>
