Assume this is the code. It accepts a CSV file, does its thing, and gives some output. Called this way:
python test.py input.csv
import numpy as np
from sklearn.svm import SVC
import sys
filename = sys.argv[-1]
val = np.genfromtxt(filename,delimiter=',')
target = val[:, 4]
features = val[:, [0,1,2,3]]
clf = SVC()
clf.fit(features, target)
print clf.predict([[6.3,2.9,5.6,1.8]])
Now I want to create a standalone executable which can run on any machine without any of the prerequisites installed (Python 2.7, numpy, sklearn, etc).
I used PyInstaller on Ubuntu 16.04 to create an executable:
pyinstaller --onefile --hidden-import sklearn.neighbors.typedefs test.py
I can use the generated executable (size ~ 55 MB) on any Ubuntu machine without any prerequisites installed:
./test input.csv
It gives identical output. So part of the problem is solved. However the documentation: https://pythonhosted.org/PyInstaller/operating-mode.html#hiding-the-source-code
states that the source code cannot be protected and suggests Cython as a remedy. I came across this StackOverflow question Cython standalone executable on ubuntu
which delineates the usage of --embed option to include the Python interpreter. But how do I embed sklearn, numpy, etc with Cython to create a truly standalone application?
The execution should be simply:
./test input.csv
and the source code shouldn't be compromised. I need help with expanding on this Cython standalone executable on ubuntu question to embed external libraries (sklearn, numpy, etc) as well.