How to install any version of Python on Northeastern's Linux server
Dennis Ping
Posted on July 20, 2022
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
Steps and explanations below:
1. Login to your Northeastern Khoury account
ssh <username>@login.khoury.northeastern.edu
Verify Python3 version
python3 --version
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
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
Activate this temp_venv
source ~/temp_venv/bin/activate
Install virtualenv
3rd party package into this temp_venv
python3 -m pip install virtualenv
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
Deactivate and delete temp_venv
deactivate
rm -r ~/temp_venv
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
5. Freedom!
Activate and deactivate your Python 3.10.5 virtual environment with these 2 commands
activate
deactivate
You should see a new label in your terminal prompt whenever activated
(python3.10) -bash-4.2$
Verify that it's indeed the correct version (3.10.5)
python3 --version
Install anything you want!
python3 -m pip install numpy pandas matplotlib scikit-learn
Check your installed pip packages
python3 -m pip list
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.
Posted on July 20, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.