python schemdraw AttributeError: __enter__

Solution 1:

schemdraw didn't add the context manager until the most recent version. You can find the commit here.

Unless you installed version 0.14 which was released on January 9, 2022, you won't have access to the context manager.

You can see version 0.13 examples do not utilize it.

import schemdraw
import schemdraw.elements as elm
d = schemdraw.Drawing()
d += elm.Resistor().label('100KΩ')
d += elm.Capacitor().down().label('0.1μF', loc='bottom')
d += elm.Line().left()
d += elm.Ground()
d += elm.SourceV().up().label('10V'))
d.draw()
d.save('schematic.svg')

But the 0.14 examples do.

import schemdraw
import schemdraw.elements as elm
with schemdraw.Drawing(file='schematic.svg') as d:
    d += elm.Resistor().label('100KΩ')
    d += elm.Capacitor().down().label('0.1μF', loc='bottom')
    d += elm.Line().left()
    d += elm.Ground()
    d += elm.SourceV().up().label('10V')