为了安装 cython(适用于 python 2.7、windows 8.1),以 .zip 格式下载,解压整个文件并运行 setup.py 。因此,python shell 显示:无法找到 pgen,未编译正式语法。
问题是什么以及如何解决?
setup.py中的相关代码首先尝试查找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.")
Run Code Online (Sandbox Code Playgroud)
如果找到pgen ,则将文件作为pgen 的Cython/Parser/Grammar参数给出
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'),
])
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)
该评论似乎表明即使pgen可用,它生成的代码也不会被使用。