Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to run Cython examples in SageMathCell

Hi, this is not a math question, this is a programming question.

I'm trying to run the first example at doc.sagemath.org/html/en/thematic_tutorials/cython_interface by using SageMathCell service (link).

For this, I've created a zip folder that I've stored in the cloud (Google Drive).

When I run the following python script in SageMathCell (I wrote it to test Cython capabilities in SageMath remote server), it seems good, but I can't see the output, that would be "Hello World".

This python script, after execution, ends with "Compiling ./Call_C_code/hello_sage.pyx..." without anyone else output.

Can you help me? Thanks,

import os
import tempfile
import sys
from distutils.dir_util import copy_tree

directory_name = tempfile.mkdtemp()
print(directory_name)
sys.path.append(directory_name)

#https://drive.google.com/open?id=129vvaCzB0M5iuPxdSdNWRG5A2gG0DwEu

import urllib
url = "https://drive.google.com/uc?export=download&id=129vvaCzB0M5iuPxdSdNWRG5A2gG0DwEu"
filename = "/Call_C_code.zip"
urllib.urlretrieve(url, directory_name + filename)

# opening the zip file in READ mode
from zipfile import ZipFile
os.chdir(directory_name)
file_name = "Call_C_code.zip"

with ZipFile(file_name, 'r') as zip:
    # extracting all the files
    print('Extracting all the files now...')
    zip.extractall()
    print('Done!')

print(sys.path)
print (os.getcwd())

for root, dirs, files in os.walk("."):  
    for filename in files:
        print(filename)

#############
%runfile Call_C_code/hello_sage.pyx
my_bridge_function()

How to run Cython examples in SageMathCell

Hi, this is not a math question, this is a programming question.

I'm trying to run the first example at doc.sagemath.org/html/en/thematic_tutorials/cython_interface by using SageMathCell service (link).

For this, I've created a zip folder that I've stored in the cloud (Google Drive).

When I run the following python script in SageMathCell (I wrote it to test Cython capabilities in SageMath remote server), it seems good, but I can't see the output, that would be "Hello World".

This python script, after execution, ends with "Compiling ./Call_C_code/hello_sage.pyx..." without anyone else output.

Can you help me? Thanks,

import os
import tempfile
import sys
from distutils.dir_util import copy_tree

directory_name = tempfile.mkdtemp()
print(directory_name)
sys.path.append(directory_name)

#https://drive.google.com/open?id=129vvaCzB0M5iuPxdSdNWRG5A2gG0DwEu

import urllib
url = "https://drive.google.com/uc?export=download&id=129vvaCzB0M5iuPxdSdNWRG5A2gG0DwEu"
filename = "/Call_C_code.zip"
urllib.urlretrieve(url, directory_name + filename)

# opening the zip file in READ mode
from zipfile import ZipFile
os.chdir(directory_name)
file_name = "Call_C_code.zip"

with ZipFile(file_name, 'r') as zip:
    # extracting all the files
    print('Extracting all the files now...')
    zip.extractall()
    print('Done!')

print(sys.path)
print (os.getcwd())
print(os.getcwd())

for root, dirs, files in os.walk("."):  
    for filename in files:
        print(filename)

#############
%runfile Call_C_code/hello_sage.pyx
my_bridge_function()