Compile and install your C ++ program using python setup.py
My Python projects depend on a C ++ program. I want to create a python package that compiles and installs this program into a virtual environment. The program should appear in the current PATH.
I tried to register the source files with a parameter ext_modules
, but it creates a .so module. Not exactly what I need.
Is there a way to achieve this?
source to share
You can run shell commands in python, that should be enough to compile the code.
import os
os.system ("make -C /path/to/makefile")
You can also run the resulting object file as a subprocess;
import subprocess
theCProcess = subprocess.Popen('/path/to/object/file')
or
theCProcess = subprocess.Popen(['/path/to/object/file', 'some', 'extra', 'arguments'])
And what do you mean by PATH? Do you mean the bash PATH variable? Usually this should remain permanent as /usr/local/bin:/usr/bin:/bin
you can put your binary in these directories, but only if you want it to be available on the system.
source to share