DEV Community

Cover image for How to install any version of Python on Northeastern's Linux server
Dennis Ping
Dennis Ping

Posted on • Updated on

How to install any version of Python on Northeastern's Linux server

Problem

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! 😥

Goal

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).

I don't care. Just give me the script!

Copy paste this entire code block into your terminal after logging into the Linux server.

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 && 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 >> .bash_profile
source .bash_profile
activate
Enter fullscreen mode Exit fullscreen mode

Steps and explanations below:

1. Login to your Northeastern Khoury account

ssh <username>@login.khoury.northeastern.edu
Enter fullscreen mode Exit fullscreen mode

Verify Python3 version

python3 --version
Enter fullscreen mode Exit fullscreen mode

You should see python 3.6.8 which is Northeastern's default Python.

2. Download your desired Python version

Since we are blocked from installing a fresh version of Python, we need to use a prebuilt portable version. Luckily, someone on Github has already prebuilt the binaries for Windows, Mac, and Linux.

We are looking for:

  • Python 3.10.5
  • Targeting Linux GNU
  • x86_64 bit v3 (for Intel Haswell 2013 and above)
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 && mv python PortablePython
Enter fullscreen mode Exit fullscreen mode

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

3. Create virtual environment #1

Create a temporary virtual environment called temp_venv in your home directory

python3 -venv ~/temp_venv
Enter fullscreen mode Exit fullscreen mode

Activate this temp_venv

source ~/temp_venv/bin/activate
Enter fullscreen mode Exit fullscreen mode

Install virtualenv 3rd party package into this temp_venv

python3 -m pip install virtualenv
Enter fullscreen mode Exit fullscreen mode

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

4. Create virtual environment #2

Create a permanent virtual environment called Python3.10 (or whatever you like). I recommend a short, descriptive name. Create it in your HOME directory for simplicity sake.

virtualenv -p=~/PortablePython/bin/python3.10 ~/Python3.10
Enter fullscreen mode Exit fullscreen mode

Deactivate and delete temp_venv

deactivate
rm -r ~/temp_venv
Enter fullscreen mode Exit fullscreen mode

Create an alias command so we can point our Linux machine to use Python3.10

if [ ! -e .bash_profile ]; then touch .bash_profile; fi;
echo alias activate="cd ~; source Python3.10/bin/activate >> .bash_profile
source .bash_profile
Enter fullscreen mode Exit fullscreen mode

5. Freedom!

Activate and deactivate your Python 3.10.5 virtual environment with these 2 commands

activate
deactivate
Enter fullscreen mode Exit fullscreen mode

You should see a new label in your terminal prompt whenever activated

(python3.10) -bash-4.2$
Enter fullscreen mode Exit fullscreen mode

Verify that it's indeed the correct version (3.10.5)

python3 --version
Enter fullscreen mode Exit fullscreen mode

Install anything you want!

python3 -m pip install numpy pandas matplotlib scikit-learn
Enter fullscreen mode Exit fullscreen mode

Check your installed pip packages

python3 -m pip list
Enter fullscreen mode Exit fullscreen mode

Notes

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

Top comments (0)