Python attachment

I would like to have one big binary file in which the Python interpreter and a small script are built-in - I am completely new to this static layout, setup and creation and GCC, etc. Please, can someone describe to me the basic steps in creating such an executable file?

I'm on MacOS 10.6, I downloaded the beta version of Python 3.3. Then I created "test.c":

#include <Python.h>

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

Now in the folder I have the folder "Python-3.3.0b1" and "test.c".

I typed:

gcc -I ./Python-3.3.0b1 -o test test.c

but I got a lot of "include" errors.

But I'm not even sure that this is the right way. Should I first build only Python somehow, and then "link" it to "test.c"?

Btw., Python , "./configure" "make"? ( ) Python, , python.org?

, "./configure" "make" "build/lib.macosx-10.6-x86_64-3.3" .so, "python" ...?

+5
3

, gcc Python . distutils , gcc. "" Python.

. script, pymkfile.py, make, . . 4 .

4 - , :

Python - PyRun_SimpleString(). . , Python, , , PyRun_SimpleString . , Python :

#include <Python.h>
int main()
{
printf("String execution\n");
Py_Initialize();
PyRun_SimpleString("import string");
PyRun_SimpleString("words = string.split('rod jane freddy')");
PyRun_SimpleString("print string.join(words,', ')");
Py_Finalize();
return 0;
}

, . Python. , pystring.c. script Makefile:

$ pymkfile.py pystring > Makefile

make, . , , , :

$ ./pystring

String execution
rod, jane, freddy

Python C. , Python . , , , . Python C.

, , ; , , : .

+2

, "./configure" "make" "build/lib.macosx-10.6-x86_64-3.3" *.so(?) "python" ...?

.so . python , make install, :

./configure
make
make install

sudo

, Python. .

OS X, , OS X Python. Python, Python. Python libpython.dylib /usr/lib

If you don't mind using Xcode just built into Google Python OS X and find a good tutorial.

I used IT the first time I did this.

+1
source

All Articles