On Monday, April 23, 2018 at 8:41:30 PM UTC-7, Martin R wrote:
>
> Hi there,
>
> Since 8.2.rc0 (the update to cython 0.28.1) I'm having trouble using 
> pyximport.  Here is a minimal non working example:
>
> ######## minimal.py ############
> import pyximport; pyximport.install();
> from minimal_pyx import minimal_fun
> ######## end minimal.py ############
>
> ######## minimal_pyx.pyx ############
> from sage.misc.cachefunc        import cached_method
>
> def minimal_fun():
>     print("hi")
> ######## end minimal_pyx.pyx ############
>
> Running this with "sage minimal.py" fails as reproduced below.
>
> It seems that I should somehow set the compile_time_env variable 
> 'PY_VERSION_HEX', and set it to sys.hexversion.  I don't know how to do 
> that (especially not when using pyximport), and I'm puzzled because I would 
> have thought that dict_del_by_value.pyx is already compiled...
>
> Thanks for any hints or workarounds!
>
> Martin
>

The problem seems to be that pyximport gets its hooks a little too deeply 
into the import system (see the documentation: they warn that pyximport 
only works in simple cases).

In this case, it seems that "import sage.misc.cachefunc" tries to do a 
little too much when the pyximport hook is active. A workaround is to make 
sure it's imported before the hook is activated, i.e.,

import sage.misc.cachefunc
import pyximport; pyximport.install();
from minimal_pyx import minimal_fun

seems to do the trick.

To cover all cases, perhaps try "import sage.all" before activating the 
hook. That should get you into a state that's comparable to what you have 
at the sage prompt. Quoting from the cython manual:

This allows you to automatically run Cython on every .pyx that Python is 
> trying to import. You should use this for simple Cython builds only where 
> no extra C libraries and no special building setup is needed.
>

ostensibly, sage doesn't qualify; so I think it's not a bug that you need a 
workaround.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to