Trying to extend Python with C: undefined reference to `Py_BuildValue'

2008-06-04 Thread spectrumdt
  Hello.

  I am trying to extend Python with some C code. I made a trivial
"Hello World" program in C that I am trying to wrap in "boilerplate"
for inclusion in a Python program. But I can't compile the C code. The
C compiler cannot find the required function `Py_BuildValue'.

  My C code looks like this:



  #include "/usr/include/python2.5/Python.h"

  /* Python wrapper for 'main'. */
  static PyObject* mpi_main() {
int res = main();
PyObject* retval = (PyObject*)Py_BuildValue("i",res);
  }

  /* Main. A 'Hello World' function. */
  int main() {
printf ("Hello, World. I am a C function.\n");
  }



  And my error message looks like this:



  [EMAIL PROTECTED] Opgave03]$ gcc ctest.c
  /tmp/ccH46bs8.o: In function `mpi_main':
  ctest.c:(.text+0x1d): undefined reference to `Py_BuildValue'
  collect2: ld returned 1 exit status
  [EMAIL PROTECTED] Opgave03]$



  I searched the newsgroup and found this thread:

 
http://groups.google.com/group/comp.lang.python/browse_thread/thread/c6d70e02a6bc9528/87b836f369bd0042?lnk=gst&q=undefined+reference+to+%60Py_BuildValue%27#87b836f369bd0042

  It recommended that I add the option "-Wl,--export-dynamic" when
calling gcc. That makes no difference. The thread also has some more
stuff that I don't quite understand.

  Can anyone help? I am including Python.h, so why does it not find
Py_BuildValue?

  Thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to extend Python with C: undefined reference to `Py_BuildValue'

2008-06-04 Thread spectrumdt
On Jun 4, 4:13 pm, Ivan Illarionov <[EMAIL PROTECTED]> wrote:
> Hi! Your C code contains too many errors. I'm lazy to comment them all.
>
> 2. create 'buildme.py' file with this content:
>

Thanks for the replies.

Maybe I should have read the rest of the guide to extending Python
with C before whining here. I hadn't noticed the part where I was
supposed to create a script to compile my C code rather than just call
gcc. I fixed that, and now it works. Thanks.

Yeah, my C code is probably full of bugs, too. I am a sucky C
programmer. :P
--
http://mail.python.org/mailman/listinfo/python-list


Extending Python with C: Can I specify another C compiler?

2008-06-04 Thread spectrumdt
  Hello.

  I am trying to extend my Python program with some C code.

  This thread is sort of a follow-up to another thread of mine, linked
below. I don't know what the conventions are in this newsgroup about
creating new threads vs. staying in existing ones, but I figured I'd
rather make a new one with a title pertaining to my current problem.

  
http://groups.google.com/group/comp.lang.python/browse_thread/thread/d60449f4db19f731#

  Anyway, my question is this: When compiling my C code to include in
Python, using a Python script with the function
distutils.core.setup... can I choose which C compiler to use? On my
system it defaults to gcc, but I would like to use mpicc instead (C
compiler for MPI, Message Passing Interface).

  Can I do this?

  My system, in case it matters, is Fedora Linux.

  Thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Extending Python with C: Can I specify another C compiler?

2008-06-04 Thread spectrumdt
On Jun 4, 6:25 pm, Gerhard Häring <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> >   Hello.
>
> >   I am trying to extend my Python program with some C code. [...]
> >   Anyway, my question is this: When compiling my C code to include in
> > Python, using a Python script with the function
> > distutils.core.setup... can I choose which C compiler to use? On my
> > system it defaults to gcc, but I would like to use mpicc instead (C
> > compiler for MPI, Message Passing Interface). [...]
>
> Try:
>
> $ export CC=mpicc
> $ python setup.py build
>
> HTH,
>
> -- Gerhard

Yes, that worked. Thank you. :)
--
http://mail.python.org/mailman/listinfo/python-list


Cannot install Pypvm (Python Parallel Virtual Machine)

2008-05-06 Thread spectrumdt
Hello.

I am trying to install Pypvm (http://pypvm.sourceforge.net/), the
Python interface to PVM ("Parallel Virtual Machine"). Unfortunately,
installation fails. I am hoping someone can help me fix it.

I am running Fedora Core 8 Linux.

The official Pypvm documentation is very helpful (or something),
providing the following:



To build Pypvm, cross your fingers and try:

make -f Makefile.pre.in boot
make

Or alternatively, try
  python setup.py build
  python setup.py install



For me, the "make -f Makefile.pre.in boot" seems to run fine, but the
"make" fails, giving (among other things) the following:



[EMAIL PROTECTED] pypvm-0.94]$ make
gcc -pthread -fPIC -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2
  -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -
march=i386
  -mtune=generic -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC
  -I/usr/include/python2.5 -I/usr/lib/python2.5/config-c
  ././pypvm_coremodule.c -o ./pypvm_coremodule.o
././pypvm_coremodule.c:2:18: error: pvm3.h: No such file or directory
././pypvm_coremodule.c: In function ‘was_error’:
././pypvm_coremodule.c:81: error: ‘PvmOk’ undeclared (first use in
this function)
././pypvm_coremodule.c:81: error: (Each undeclared identifier is
reported only once
././pypvm_coremodule.c:81: error: for each function it appears in.)
././pypvm_coremodule.c:85: error: ‘PvmBadParam’ undeclared (first use
in this function)
././pypvm_coremodule.c:85: error: ‘PvmMismatch’ undeclared (first use
in this function)
[...]
././pypvm_coremodule.c:1889: error: ‘PvmDupEntry’ undeclared (first
use in this function)
././pypvm_coremodule.c:1767: warning: unused variable ‘optModule’
././pypvm_coremodule.c:1766: warning: unused variable ‘resultModule’
././pypvm_coremodule.c:1765: warning: unused variable ‘notifyModule’
././pypvm_coremodule.c:1764: warning: unused variable ‘spawnModule’
././pypvm_coremodule.c:1763: warning: unused variable ‘dataModule’
././pypvm_coremodule.c:1762: warning: unused variable
‘exceptionModule’
make: *** [pypvm_coremodule.o] Error 1
[EMAIL PROTECTED] pypvm-0.94]$



In in alternate version, "python setup.py build" similarly fails:



[EMAIL PROTECTED] pypvm-0.94]$ python setup.py build
running build
running build_py
running build_ext
building 'pypvm_core' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-
D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-
size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -
D_GNU_SOURCE -fPIC -fPIC -I/usr/include -I/usr/include/python2.5 -c
pypvm_coremodule.c -o build/temp.linux-i686-2.5/pypvm_coremodule.o
pypvm_coremodule.c:2:18: error: pvm3.h: No such file or directory
pypvm_coremodule.c: In function ‘was_error’:
pypvm_coremodule.c:81: error: ‘PvmOk’ undeclared (first use in this
function)
pypvm_coremodule.c:81: error: (Each undeclared identifier is reported
only once
pypvm_coremodule.c:81: error: for each function it appears in.)
pypvm_coremodule.c:85: error: ‘PvmBadParam’ undeclared (first use in
this function)
[...]
pypvm_coremodule.c:1889: error: ‘PvmDupEntry’ undeclared (first use in
this function)
pypvm_coremodule.c:1767: warning: unused variable ‘optModule’
pypvm_coremodule.c:1766: warning: unused variable ‘resultModule’
pypvm_coremodule.c:1765: warning: unused variable ‘notifyModule’
pypvm_coremodule.c:1764: warning: unused variable ‘spawnModule’
pypvm_coremodule.c:1763: warning: unused variable ‘dataModule’
pypvm_coremodule.c:1762: warning: unused variable ‘exceptionModule’
error: command 'gcc' failed with exit status 1
[EMAIL PROTECTED] pypvm-0.94]$



Can anyone help me get it to work?

Thanks in advance.
- Claus Appel
--
http://mail.python.org/mailman/listinfo/python-list


How to kill Python interpreter from the command line?

2008-05-08 Thread spectrumdt
Hello.

I am running Fedora Linux and KDE, using the Konsole command line.

When coding Python, I regularly make a bug causing my program to not
terminate. But how do I kill the non-terminating Python interpreter
without killing the entire Konsole?

The default way of killing the current process on the command line is
Ctrl+C, but that doesn't work with Python. Neither do the "terminate
task", "suspend task" or "interrupt task" commands (available from
right-click in Konsole).

So, can someone please help? How do I kill Python without having to
restart Konsole?

Thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to kill Python interpreter from the command line?

2008-05-09 Thread spectrumdt
Thanks for all the replies.

On May 8, 5:50 pm, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
> Ctrl+C often works with Python, but as with any language, it's possible
> to write a program which will not respond to it.  You can use Ctrl+\
> instead (Ctrl+C sends SIGINT which can be masked or otherwise ignored,
> Ctrl+\ sends SIGQUIT which typically isn't)

Yes, thank you, this seems to work. :)

I did some more testing and found out that the problem seems to be
thread-related. If I have a single-threaded program, then Ctrl+C
usually works, but if I have threads, it is usually ignored. For
instance, the below program does not respond to Ctrl+C (but it does
die when issued Ctrl+\):



import threading

def loop():
  while True:
pass

threading.Thread(target=loop,args=()).start()
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to kill Python interpreter from the command line?

2008-05-09 Thread spectrumdt

Thanks for the replies.

On May 8, 5:50 pm, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
> Ctrl+C often works with Python, but as with any language, it's possible
> to write a program which will not respond to it.  You can use Ctrl+\
> instead (Ctrl+C sends SIGINT which can be masked or otherwise ignored,
> Ctrl+\ sends SIGQUIT which typically isn't)

Yes, thank you, this seems to work. :)

I did some more testing and found out that the problem seems to be
thread-related. If I have a single-threaded program, then Ctrl+C
usually works, but if I have threads, it is usually ignored. For
instance, the below program does not respond to Ctrl+C (but it does
die when issued Ctrl+\):



import threading

def loop():
  while True:
pass

threading.Thread(target=loop,args=()).start()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Cannot install Pypvm (Python Parallel Virtual Machine)

2008-05-09 Thread spectrumdt
Thanks for the reply.

I've found and installed the package containing pvm3.h. (The file is
now located under "share/pvm3/include/pvm3.h".) But Pypvm can't find
it.

Someone recommended that I install the equivalent of what is called
"build-essential" in Ubuntu. I was told that the equivalent can be
achieved in Fedora like this:

sudo yum groupinstall "Development Tools" --exclude=systemtap --
exclude=systemtap-runtime

I don't quite understand what these packages are supposed to do, but
they don't seem to help.

Can anyone tell me how to make (the installation program for) Pypvm
understand where the header file is?

Thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list