Load_circuit failing for some reasons

  • OS: MacOS Catilina (version 10.15.7)
  • Python framework with PyCharm + Conda environment
  • PySpice installed with Conda (version 1.4.3)
  • libngspice installed with Conda
  • NGSPICE installed with homebrew (version 33)
    • location: /usr/local/bin/ngspice
    • functionality check: NGSPICE works from terminal and does simulate a circuit


this is my first test with the “PySpice” flow. I went through the explained installation steps:

By running the “resistor-bridge.py” example:

I get the following error:

PySpice.Spice.NgSpice.Shared.NgSpiceCommandError: Command ‘run’ failed

By placing a breakpoint and debugging the code I see that the failing point is at (every line nested hierarchically):

analysis = simulator.operating_point()
return self._run(‘operating_point’, *args, **kwargs)
raise NgSpiceCommandError(“Command ‘{}’ failed”.format(command))

And is due to stderr = ‘Error: there aren’t any circuits loaded.’

By debugging further I could nail down that the def run() method of the Simulation class fails because the run command after the load_circuit command complains that the circuit wasn’t loaded.

def _run(self, analysis_method, *args, **kwargs):

    super()._run(analysis_method, *args, **kwargs)

    # Fixme: Error: circuit not parsed.

    plot_name = self._ngspice_shared.last_plot
    if plot_name == 'const':
        raise NameError('Simulation failed')

    return self._ngspice_shared.plot(self, plot_name).to_analysis()

So the load_circuit method seems to not load the circuit properly in the sim, any idea why? (although it does execute it and no error is raised within that method).

I tried also the listing() method to query the circuit description back and also doesn’t seem to provide anything back.

Actually the only communication with the simulator seems to be successful is the “version -f” command which returns the valuable infos from it.


Hi Andrea,

I have been having a similar issue as you, with the same setup and same resulting errors.

I am not sure what the root cause of the issue is, and have a feeling it may be some sort of version incompatibility with the libngspice shared library. (In theory ngspice shouldn’t need to be installed for PySpice to work, other than for linking the spinit config file)

The solution I have been able to find is to set DEFAULT_SIMULATOR to “ngspice-subprocess”, as described here

To implement this, update line 26 of the resistor-bridge.py example file to the following:

simulator = circuit.simulator(simulator="ngspice-subprocess", temperature=25, nominal_temperature=25)

This change should run the spice server using the ngspice subprocess. (Note: I needed to update my PATH to point to the ngspice bin dir, which was installed funny by Homebrew - export PATH=$PATH:/usr/local/Cellar/ngspice/33/bin)

> python3 examples/resistor/resistor-bridge.py

2020-12-30 22:38:24,084 - PySpice.Spice.NgSpice.Server.SpiceServer - Server.INFO - Start the spice subprocess
Node 1: 10.0 V
Node 2: 4.0 V
Node 3: 6.0 V

My other solution was to create a lightweight Python Dockerfile with pyspice installed for running my analyses. I can post that Dockerfile here if you wish

This is not the ideal solution, but hopefully this helps get the examples running


You are awesome! Thanks for the help, I was losing hope in the meanwhile :slight_smile: Will give it a try and let you know…thx! (and happy new year!)