At my job, I have an older machine that runs on Linux that is not connected to the internet. It has Python 2.4.3 pre-installed, but I need to make use of some libraries that the machine does not have. Ideally, I would like to have Python 3.6 or higher, since I have experience/finished code already made for this version.
For reference, I will copy a bit of the hardest code I have that will need to run on the computer in question (This is a module to make a 2D color plot from three columns of data with varying lengths of values):
import matplotlib.pyplot as plt
from matplotlib.colors import BoundaryNorm
from matplotlib.colors import LogNorm
import numpy as np
import pylab as plb
import scipy.interpolate
from scipy.optimize import curve_fit
from scipy import asarray as ar,exp
import math as mt
data = 'aupnipam_scan41_3DFLR.txt'
f = np.genfromtxt(data)
x = f[:,][:,0]
y = f[:,][:,1]
z = f[:,][:,2]
i = 0
t = 0
xmatrix = [[0 for x in range(26)] for y in range(1024)]
ymatrix = [[0 for x in range(26)] for y in range(1024)]
zmatrix = [[0 for x in range(26)] for y in range(1024)]
while (i < 26):
j = 0
while (j < 1024):
xmatrix[j][i] = x[t]
j = j+1
t = t+1024
i = i+1
i = 0
j = 0
t = 0
while (j < 1024):
i = 0
while (i < 26):
ymatrix[j][i] = y[j]
i = i+1
j = j+1
i = 0
j = 0
while (i < 26):
j = 0
while (j < 1024 and t < 26624):
if(z[t] == 0):
z[t] = 0.1
zmatrix[j][i] = z[t]
j = j+1
t = t+1
i = i+1
t = t+1
levels = np.linspace(0, 50, 51)
cmap = plt.get_cmap('magma')
norm = LogNorm(1, 100, clip=True)
im = plt.pcolormesh(xmatrix, ymatrix, zmatrix, cmap=cmap, norm=norm)
plt.colorbar(im)
plt.show()
Now, I suppose my real question is what is the easiest way to get my code running here? I do fairly basic number-crunching, nothing too difficult as you can see; I am confident Python 2.4 is more than capable of running this, but I will need matplotlib, scipy, etc. to run what I have.
There might be a way to get the machine connected to the internet temporarily to install what I need, but I work for an extension of the US Department of Energy and doing so is a major hassle. Alternatively, I would very much like to drop my installation of Python 3.6 onto a USB to copy it over and set the environment path manually on the Linux device. Will this work? Do I need to uninstall Python 2.4 first? Are there any other steps/complications in doing this? I know that powering through and making my own code that doesn't use libraries is possible, but I don't think I have the coding skills to make that happen.
I am aware of the couple of possibilities mentioned above, but I'm not totally sure how to actually get them done; maybe somebody who has gone through this process or something similar can help. I've tried flipping through online guides to get python+libraries working on a Linux device, but all that I've seen assume internet connectivity. Any help is greatly appreciated, thank you in advance!
I like your solution of putting your Python 3.6 on a USB stick. Probably the easiest way to do this (which I have not tried) would be:
On your internet-connected machine, create a virtualenv on your USB stick (
virtualenv /path/to/usb/whatever)With your virtualenv activated, install your supporting packages. (
pip install....).Take your USB stick to your air-gapped machine. Insert it. If your site security officer does not freak out at this point, you are doing something wrong. :)
Activate your virtualenv on the air-gapped machine (
source /path/to/usb/whatever/bin/activate)Now you should be able to run
python myscript.pyOh wait...I forgot something. If any of your supporting libraries depend on system libraries (and IIRC, numpy depends on the BLAS libraries, among others), I think you might be SOL.