2

I recently needed a static version of python in one of my projects, so i got the source and built it. After linking it to my application when I run it I am missing all of the required modules and I don't know where to put them.

Errors:

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
'import site' failed; use -v for traceback
Traceback (most recent call last):
    File "<string>", line 1, in <module>
ImportError: No module named time

Code:

#include <Python.h>

int main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]);  /* optional but recommended */
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
                 "print 'Today is',ctime(time())\n");
Py_Finalize();
return 0;

}

Code for building exe:

gcc main.c -I/Desktop/Python-2.6.4 -I//Desktop/Python-2.6.4/Include -I/Desktop/Python-2.6.4/Modules -L/Desktop/Python-2.6.4 -lpython2.6 -static

Tutorial for building python statically

If someone could tell me where to put these modules or even better tell me how to link them statically, it would be much appreciated!

0xSingularity
  • 577
  • 6
  • 36

1 Answers1

0

Don't have an answer to your question, but I would suggest trying a portable Python distribution like these:

Some of them are geared towards scientific computing, but especially pyrun or portablepython should provide you with a small package.

There are even more options, maybe one of them solves your problem.

jeverling
  • 2,004
  • 1
  • 20
  • 21
  • 1
    im not sure about the portable python install, because it is huge. The installiation itself is roughly 250mb, I just need the modules included which is roughly 20mb. I'll consider it but i don't think i can implement this in such a small app. Thanks for your answer! – 0xSingularity Jan 10 '15 at 17:42
  • What exactly is it that you want to achieve in the end? You are on Windows, right? Maybe building an executable with py2exe or another solution (http://docs.python-guide.org/en/latest/shipping/freezing/) could work? You should be able to include only modules that your application needs. – jeverling Jan 11 '15 at 11:44
  • I just installed PortablePython in Wine, after deselecting all the modules the size was down to 50MB. I think if you delete everything that isn't needed (you can use https://docs.python.org/3.4/library/modulefinder.html to see which modules you have to include) you should be able to bring the size down much further. If you just want to ship a python project I would check the freezing solutions. – jeverling Jan 11 '15 at 11:54
  • 1
    I want to be able to view and execute python code directly from C code without the user having to have python installed. I don't think I could achieve this from freezing? – 0xSingularity Jan 11 '15 at 20:05
  • Ah, in this case I think you are right and freezing is not going to help you. I don't think I can help you with that problem, maybe you will find something useful here: http://stackoverflow.com/a/1056057/204706 Best of luck! – jeverling Jan 11 '15 at 23:01