0

I made a .py file called "hello.py" which has the following imports:

from setuptools import setup,Extension
from Cython.Build import cythonize
setup( name = 'increment app',ext_modules = cythonize("hello.pyx"))

While running this I am getting an:

AttributeError :'module' object has no attribute 'locals'.

I am working with Visual Studio C++ 2008 version.

Command prompt pip install cython gave me no error but it didn't download or install cython either .

@DavidW Here is the full traceback ---

AttributeErrorTraceback (most recent call last)
C:\SPB_Data\setup.py in <module>()
      1 from setuptools import setup,Extension
----> 2 from Cython.Build import cythonize
      3 setup( name = 'increment app',ext_modules = cythonize("hello.pyx"))
C:\Users\kalachand\AppData\Local\Enthought\Canopy32\edm\envs\User\lib\site-packages\Cython\Build\__init__.py in <module>()
----> 1 from .Dependencies import cythonize
      2 from .Distutils import build_ext
C:\Users\kalachand\AppData\Local\Enthought\Canopy32\edm\envs\User\lib\site-packages\Cython\Build\Dependencies.py in <module>()
    176 
    177 
--> 178 @cython.locals(start=cython.Py_ssize_t, end=cython.Py_ssize_t)
    179 def line_iter(source):
    180     if isinstance(source, basestring):
AttributeError: 'module' object has no attribute 'locals' 
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Could you add the traceback? It might be useful to see where the error is occurring. – DavidW Dec 31 '17 at 08:03
  • @DavidW see the full traceback that you wanted in the answer section please. and also , is there any way I can contact you so that you can help me with the entire process. Been stuck here for 1.5 days straight. It won't take more than 15 min . Thanks .. – Wriddhiman Kumar Naharoy Dec 31 '17 at 09:21
  • This kind of thing is always difficult to fix (and it certainly isn't something I really know how to do). Have you [managed to create another module called "cython" which is getting in the way](https://stackoverflow.com/a/15130088/4657412) - check with running `import cython; print(cython.__file__)`. – DavidW Dec 31 '17 at 10:18
  • Please [edit] the traceback into a code block so that line breaks are properly preserved. I tried to guess where lines should be broken but gave up. This information is crucial for your question and needs to be properly legible. – tripleee Dec 31 '17 at 10:38
  • I managed to salvage the traceback from your now-deleted "answer". Please don't use the "Post Your Answer" button to post content which does not attempt to answer the question at the top of this page. But thanks for the traceback. – tripleee Dec 31 '17 at 10:48
  • @tripleee Yeah Thanks for the edit . I'll keep that in mind in future . – Wriddhiman Kumar Naharoy Dec 31 '17 at 11:29
  • The import error looks vaguely like Cython isn't supposed to be called like this, but you seem to be following the [Hello World example](http://cython.readthedocs.io/en/latest/src/tutorial/cython_tutorial.html#cython-hello-world) fairly closely, however with `setuptools` instead of `distutils`. Does this make a difference? How exactly are you invoking your `setup.py`? Again, please [edit] your question to update it, and check out the [formatting help](/editing-help) you get to the right of the editable textbox (in the desktop version of this site). – tripleee Dec 31 '17 at 12:11
  • @tripleee I am invoking the setup.py by normal "python" command with "build_ext --inplace" extension (just like in the http://cython.readthedocs.io/en/latest/src/tutorial/cython_tutorial.html#cython-hello-world example ) . Then it is saying "there is no module 'Cython'". – Wriddhiman Kumar Naharoy Dec 31 '17 at 12:24

1 Answers1

0

The guideline you seem to be following instructs you to put this code in setup.py and to invoke it in a fairly specific way.

python setup.py build_ext --inplace

The guideline uses distutils, not setuptools.

The guideline explains how to Cythonize some other code of yours, so the argument "hello.pyx" also looks wrong (or replace hello.py with some other code, like the simple print("Hello World") example in the guideline, and move the code in your question to setup.py like I suggest above).

If you have reasons to deviate from the documentation, you should explain your rationale for the deviation, and mention whether this particular deviation from the instructions causes your failure. Making multiple gratuitous (or not) changes without testing wastes your time and ours; see also the guidance for making your question a MCVE.

tripleee
  • 175,061
  • 34
  • 275
  • 318