Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cython setup error : Unable to find pgen, not compiling formal grammar

Tags:

python

cython

In order to install cython ( for python 2.7 , windows 8.1 ), made the download in .zip format, extracted the whole file and run the setup.py . Thus, python shell shows this : Unable to find pgen, not compiling formal grammar.

What is the problem and how it can be solved ?

like image 659
p_a321 Avatar asked Jan 30 '16 00:01

p_a321


3 Answers

Much Simpler,

Try installing Cython from pip. Windows- Open Python folder, press shift+right click, select "open command promt here"

pip install cython

like image 43
Manish Avatar answered Nov 09 '22 07:11

Manish


The relevant code in setup.py first tries to find pgen

 pgen = find_executable(
        'pgen', os.pathsep.join([os.environ['PATH'], os.path.join(get_python_inc(), '..', 'Parser')]))
    if not pgen:
        print ("Unable to find pgen, not compiling formal grammar.")

If pgen is found, then file Cython/Parser/Grammar is given as argument to pgen

    else:
        parser_dir = os.path.join(os.path.dirname(__file__), 'Cython', 'Parser')
        grammar = os.path.join(parser_dir, 'Grammar')
        subprocess.check_call([
            pgen,
            os.path.join(grammar),
            os.path.join(parser_dir, 'graminit.h'),
            os.path.join(parser_dir, 'graminit.c'),
            ])

The first lines of Cython/Parser/Grammar,

# Grammar for Cython, based on the Grammar for Python 3

# Note: This grammar is not yet used by the Cython parser and is subject to change.

That comment seems to suggests that even if pgen is available, the code produced by it won't be used.

like image 145
J.J. Hakala Avatar answered Nov 09 '22 08:11

J.J. Hakala


I had the same problem in ubuntu. I first tried

sudo easy_install cython

It failed

Then I did it manually in the following manner:

mkdir cython
cd cython
wget http://cython.org/release/Cython-0.24.zip
unzip Cython-0.24.zip
cd Cython-0.24
sudo python setup.py install
like image 1
Yonatan Simson Avatar answered Nov 09 '22 06:11

Yonatan Simson