0

I am trying to run this code sample to test swig on Ubuntu 12.04. I have python 2.7.3 installed on my system. This code seems to be for networked machines. How can I find where my python is installed and what should I replace these directory paths be?

cc -c example.c example_wrap.c \
-I/usr/local/include/python1.5 \
-I/usr/local/lib/python1.5/config
rishiag
  • 2,248
  • 9
  • 32
  • 57

2 Answers2

1

You can replace the lines with python-config --includes which automatically creates the correct statements for the compiler and your installed python version. python-config itself is installed through python-dev, which you will need in case you haven't installed it yet.

So for calling the compiler on the command line:

cc -c example.c example_wrap.c $(python-config --cflags) -fPIC

Also, python1.5? Where did you find that example?

Thomas Fenzl
  • 4,342
  • 1
  • 17
  • 25
  • Thanks. It's swig tutorial from 1998. Actually I have already replaced python-dev tools but still there was no python.h in the address that is in the example. Also now I am getting following error: example_wrap.c:2952:21: fatal error: headers.h: No such file or directory compilation terminated. – rishiag May 12 '13 at 09:30
  • There is a slightly newer tutorial at http://www.swig.org/tutorial.html. Still python2.1 ;) With my slightly edited command line, the example there works for me. If you want to interact with c-code from python, you can also take a look at http://cffi.readthedocs.org/en/latest/index.html – Thomas Fenzl May 12 '13 at 09:51
  • Thanks a lot. :) That worked fine for me. Actually I am trying to do this: http://stackoverflow.com/questions/16504795/how-do-i-integrate-c-library-with-python I want to integrate C++ library with Python. Any ideas on how it could be done? – rishiag May 12 '13 at 10:02
0

/usr/local is standard for any Posix operating system, see the Filesystem Hierarchy Standard (FHS). You you get the python version you need with apt-get (I think the command is sudo apt-get install python1.5 but I'm not on a ubuntu system at the moment so I can't try it), it will put it in the standard places, which is likely /usr/local.

To answer the other part of your question, you can find where your python is installed using which python. python is likely a symbolic link to python2.7, so you may have to explicitly run python1.5 which you can find with which python1.5 if it's been installed.

Python 1.5 is a very, very old version of Python. Where did you get the code sample from?

Codie CodeMonkey
  • 7,669
  • 2
  • 29
  • 45