3

I'd like to do some code generation, and StringTemplate looks like a pretty good tool for the job. I easy_installed stringtemplate3 from PyPi, but when I try to import it I get:

ImportError: No module named antlr

I am confused by this because I thought that ANTLR depended on StringTemplate (as the website says), not the other way around. In any case, I cannot find the correct package to fix this. Installing antlr_python_runtime did not help.

Any hints?

John Salvatier
  • 3,077
  • 4
  • 26
  • 31
  • I believe Antlr and ST have cyclic dependencies, but with one depending on an earlier version of the other. i.e. if ST 4 depends on Antlr 3, Antlr 3 depends on ST 3 rather than 4. – I82Much Apr 09 '11 at 15:51

2 Answers2

3

You need to have the python-antlr package installed to use stringtemplate3. Example of installing on Ubuntu:

% sudo aptitude install python-antlr
% virtualenv ~/virt
% . ~/virt/bin/activate
(virt)~% easy_install stringtemplate3
(virt)~% python -c 'import stringtemplate3'

FWIW this package is named py26-antlr3 on Macports (not sure which platform / package manager you're using).

samplebias
  • 37,113
  • 6
  • 107
  • 103
  • hmm, for my purposes, I need the solution to be cross platform and simple to install. I guess stringtemplate is not the solution for me. Thanks. – John Salvatier Mar 04 '11 at 22:05
  • 3
    Didn't work for me. stringtemplate3 does not use antlr3, it uses antlr2.7~ . I had to manually install it by downloading http://www.antlr2.org/download/antlr-2.7.7.tar.gz , unzipping it, navigating to antlr-2.7.7/lib/python , and running python setup.py install . After this, the dependency was met. – I82Much Apr 09 '11 at 16:10
  • 1
    The tip from @I82Much worked for me. I'm actually trying to get antlr3 to run. I got antlr-3.1.3.jar, created a virtualenv, installed antlr_python_runtime-3.1.3.tar.gz per `python setup.py install`, then `pip install stringtemplate3`, and finally installed antlr2.7 as explained above. Crazy that chain of dependencies. – jdm Jun 22 '12 at 10:04
1

I was facing the same issue and packaged the antlr python library: you can pip install git+git://github.com/kynan/antlr.git#egg=antlr to install it.

kynan
  • 13,235
  • 6
  • 79
  • 81