Hi dear sage-support group:
I was working a Differential equations problem with few elements in some regular 3D-mesh which needed not too much calculations but I am upgrading it to a bigger system. Then I shall need to do some calculations using cython, so my first task is to build the simplest Hello world example to understand how to proceed with my implementation.
But I think something is missing in my Cython installation or perhaps I am doing something wrong, because I cannot accomplish to build even this simplest cython example. I am using sage 4.1 in a Karmic Ubuntu 9.10.
In my first try I just follow the directions in the Cython's manual; first save a file with just the line:
print "hello world"
as hello.pyx and then from the command line:
python setup.py build_ext --inplace
where the setup.py file is the same as in the manual.
But I get the message:
Traceback (most recent call last):
File "setup.py", line 3, in <module>
from Cython.Distutils import build_ext
ImportError: No module named Cython.Distutils
within sage:
sage -sh
running build_ext
cythoning helloworld.pyx to helloworld.c
building 'helloworld' extension
gcc -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/sage/local/include/python2.6 -c helloworld.c -o build/temp.linux-x86_64-2.6/helloworld.o
gcc -pthread -shared build/temp.linux-x86_64-2.6/helloworld.o -o helloworld.so
it finally got built the file helloworld.c and compile and link them until reach helloworld.so
but when I try the next step:
import helloworld
/usr/bin/python: /opt/sage/local/lib/libz.so.1: no version information available (required by /usr/bin/python)
Traceback (most recent call last):
File "/usr/lib/command-not-found", line 8, in <module>
import CommandNotFound
ImportError: No module named CommandNotFound
My next try was following the directions in:
http://behnel.de/cython200910/talk.htmlwith the William Stein's file hw.py:
import sage.all
def hello_world():
import sys
print "Welcome to Sage - ", sage.all.factor(89392)
if __name__ == '__main__':
hello_world()
within sage:
cython --embed hw.py
Cython (
http://cython.org) is a compiler for code written in the
Cython language. Cython is based on Pyrex by Greg Ewing.
Usage: cython [options] sourcefile.pyx ...
Options:
-V, --version Display version number of cython compiler
-l, --create-listing Write error messages to a listing file
-I, --include-dir <directory> Search for include files in named directory
(multiply include directories are allowed).
-o, --output-file <filename> Specify name of generated C file
-r, --recursive Recursively find and compile dependencies
...
...
it seems that I don't have the option --embed, to create an embedded main() function.
If I ignore this and proceed:
cython hw.py
I get the hw.c and from here:
gcc -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/sage/local/include/python2.6 \
/opt/sage/local/lib/libpython2.6.a -o hw hw.c -lpthread -lm -lutil -ldl
(may be I exagerate a little with all the compilation parameters, but I get a
/usr/lib/gcc/x86_64-linux-gnu/4.4.1/../../../../lib/crt1.o: In function `_start':
/build/buildd/eglibc-2.10.1/csu/../sysdeps/x86_64/elf/start.S:109: undefined reference to `main'
/tmp/ccLFKVfV.o: In function `__Pyx_AddTraceback':
/home/george/hw.c:995: undefined reference to `PyString_FromString'
...
...
a bunch of more similar complains and finally
/home/george/hw.c:612: undefined reference to `PyErr_SetObject'
collect2: ld returned 1 exit status
so I need the embedded main(), could you tell me how I can proceed? (I am sorry if I extended too much).
Greetings
Jorge
¿Cómo sobrevivir en la red?
Otto de IE8 te dice cómo