4

I have recently tried using Asymptote in python. Following the directions from here:http://asymptote.sourceforge.net/doc/Interactive-mode.html, at the very bottom, it says to place the asymptote.py file on the python path. I have done this, but when I try to execute some code, it gives the error (python is installed in C:\Python27, while asymptote.py is installed in C:\Python27\Lib\site-packages):

-: 4.1: syntax error
error: could not load module '-'

The code inside of asymptote.py is pasted here:

# Python module to feed Asymptote with commands
# (modified from gnuplot.py)
from subprocess import *
class asy:
    def __init__(self):
        self.session = Popen(['asy', '-quiet', '-interactive'], stdin=PIPE)
        self.help()
    def send(self, cmd):
        self.session.stdin.write(cmd+'\n')
        self.session.stdin.flush()
    def size(self, size):
        self.send("size(%d);" % size)
    def draw(self, str):
        self.send("draw(%s);" % str)
    def fill(self, str):
        self.send("fill(%s);" % str)
    def clip(self, str):
        self.send("clip(%s);" % str)
    def label(self, str):
        self.send("label(%s);" % str)
    def shipout(self, str):
        self.send("shipout(\"%s\");" % str)
    def erase(self):
        self.send("erase();")
    def help(self):
        print "Asymptote session is open.  Available methods are:"
        print "    help(), size(int), draw(str), fill(str), clip(str), label(str), shipout(str), send(str), erase()"
    def __del__(self):
        print "closing Asymptote session..."
        self.send('quit');
        self.session.stdin.close();
        self.session.wait()
if __name__=="__main__":
    g = asy()
    g.size(200)
    g.draw("unitcircle")
    g.send("draw(unitsquare)")
    g.fill("unitsquare, blue")
    g.clip("unitcircle")
    g.label("\"$O$\", (0,0), SW")
    raw_input("press ENTER to continue")
    g.erase()
    del g

My code:

from asymptote import *
g=asy()
g.size(200)
g.draw("unitcircle")
g.send("draw(unitsquare)")
g.fill("unitsquare, blue")
g.clip("unitcircle")
g.label("\"$O$\", (0,0), SW")

I understand that asymptote.py is only meant to feed commands to asy.exe, and I have Asymptote installed on my computer. How can I resolve this error?

user111
  • 143
  • 1
  • 4

0 Answers0