I have a simple HelloWorld.g4 grammar (see it at the bottom). I am able to successfully generate the .py files using this:
set CLAS
Ran into this today as well: The problem is that the testrig expects the generated java source code. But since you're on Python you don't have it unless you explicitly run antlr4 twice: Once for target language Python2 (or 3) and once for -Dlanguage=java.
See this answer which suggests to run the language=java target first. Then the comment on the question itself to compile the java files.
And for completeness and before it's forgotten: Ensure your $CLASSPATH env variable is set up so that it includes both a dot '.' and the path to the antlr*.jar file. For example on unix:
export CLASSPATH=".://antlr-4.2.2-complete.jar:$CLASSPATH"
Here's a step by step of what I guess you have to do once the $CLASSPATH is set correctly:
Compile for java:
> antlr4 -Dlanguage=java HelloWorld.g4
# or: java org.antlr.v4.Tool -Dlanguage=java HelloWorld.g4
Note that I have the options { language=Python3 } in my grammar file and the -D override did not work as expected. So I removed the option block and specify the language target on the command line now.
Then compile the *.java files into *.class files:
> javac -g *.java
Then run the testrig:
> grun HelloWorld message
# or: java org.antlr.v4.gui.TestRig HelloWorld message -gui < input.txt