ImportError: Building module z failed: ["NameError: name 'cython' is not defined\n"] with Pure Python

21 views
Skip to first unread message

Jesus Cea

unread,
Sep 23, 2017, 2:23:27 PM9/23/17
to cython...@googlegroups.com
Sorry if this is a FAQ. I am not familiar with Cython.

Now than 0.27 supports variable annotations, I try to write ".py" files
instead of ".pyx" files. The idea is to be able to run the code in the
interpreter for development and debugging, but being fast in production.

I have this example code:

"""
import cython

def a(x:cython.int, y:cython.int) -> cython.int:
i:cython.int
x2:cython.int = 0

for i in range(y):
x2 += x

return x2

if cython.compiled:
print("COMPILED")
else:
print("Interpreted")

#import time
#t = time.time()
#a(567,17913453)
#print(time.time()-t)
"""

If this code is called "z.pyx", it works fine and fast. If it is called
"z.py", it compiles but imports fails with:

"""
ImportError: Building module z failed: ["NameError: name 'cython' is not
defined\n"]
"""

Reading the documentation, it seems than "pure python" + annotations
modules would be supported.

I have tried both the "setup.py" and "pyximport.install(inplace=True,
build_in_temp=False,pyimport=True)" options.

I am doing it wrong?. Is this a bug?.

Excuse me if this is a FAQ and I am wasting your time.

Thanks for your time and hard work!.

--
Jesús Cea Avión _/_/ _/_/_/ _/_/_/
jc...@jcea.es - http://www.jcea.es/ _/_/ _/_/ _/_/ _/_/ _/_/
Twitter: @jcea _/_/ _/_/ _/_/_/_/_/
jabber / xmpp:jc...@jabber.org _/_/ _/_/ _/_/ _/_/ _/_/
"Things are not so easy" _/_/ _/_/ _/_/ _/_/ _/_/ _/_/
"My name is Dump, Core Dump" _/_/_/ _/_/_/ _/_/ _/_/
"El amor es poner tu felicidad en la felicidad de otro" - Leibniz

signature.asc

Stefan Behnel

unread,
Sep 26, 2017, 6:21:46 PM9/26/17
to cython...@googlegroups.com
Yes, it's a bug. Thanks for the report. This hopefully fixes it:

https://github.com/cython/cython/commit/c95bae90113cb3df37674b7a2c2a37eb6b9765c3

Could you try the latest master?

Stefan

Jesus Cea

unread,
Oct 3, 2017, 8:49:26 PM10/3/17
to cython...@googlegroups.com
On 27/09/17 00:21, Stefan Behnel wrote:
> Jesus Cea schrieb am 23.09.2017 um 16:15:
[...]
>> """
>> ImportError: Building module z failed: ["NameError: name 'cython' is not
>> defined\n"]
>> """
[...]>> I am doing it wrong?. Is this a bug?.
>
> Yes, it's a bug. Thanks for the report. This hopefully fixes it:
>
> https://github.com/cython/cython/commit/c95bae90113cb3df37674b7a2c2a37eb6b9765c3
>
> Could you try the latest master?

Sorry, I read your reply too late. I can confirm that 0.27.1, just
released, solves the issue. Thanks.
signature.asc
Reply all
Reply to author
Forward
0 new messages