OSError: cannot load library 'libngspice.so':

Good afternoon community, I am writing to you because I have encountered the following error trying to simulate the following filter that appears in the documentation.


The error is as follows.
2020-05-23 00:45:37,954 - PySpice.Spice.NgSpice.Shared.NgSpiceShared.new_instance - INFO - New instance for id 0
2020-05-23 00:45:37,955 - PySpice.Spice.NgSpice.Shared.NgSpiceShared._load_library - WARNING - Set locale LC_NUMERIC to C


OSError                                   Traceback (most recent call last)

<ipython-input-6-475d4280ae1b> in <module>()
----> 1 simulator = circuit.simulator(temperature=25, nominal_temperature=25)
      2 analysis = simulator.ac(start_frequency=1@u_Hz, stop_frequency=1@u_MHz, number_of_points=10,  variation='dec')

8 frames

/usr/local/lib/python3.6/dist-packages/cffi/api.py in _load_backend_lib(backend, name, flags)
    825         if first_error is not None:
    826             msg = "%s.  Additionally, %s" % (first_error, msg)
--> 827         raise OSError(msg)
    828     return backend.load_library(path, flags)

OSError: cannot load library 'libngspice.so': libngspice.so: cannot open shared object file: No such file or directory.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libngspice.so'

I have installed all the dependencies, although I have run out of ideas, I am starting in the world of programming, however, they asked me for a job to simulate filters in the university. I need your help, if possible, a lot of fat in advance

Please provide infos about your environment :
OS, Python version, PySpice version, simulator

From your very incomplete infos, (I guess you are on linux from what I read) :

  1. libngspice is not installed ; or,
  2. LD_LIBRARY is not properly set

pyscpice 1.4.2, python 3.6.2, Ubuntu 18.04.4 LTS, i couldn’t install libngspice

I have tried to install the libngspice library in ubuntu but it did not succeed it tells me that it cannot find it

On Ubuntu, libngspice is only available for 19.10 and after :
That is why you cannot install it on 18.04

From that point, you can either

  • compile the library by yourself (which I suspect, is beyond your knowledge) ;
  • download the package and its dependencies from packages.ubuntu.com, arrange the library and set the LD_LIBRARY_PATH (which may also be a not trivial operation for you)
  • create a virtual machine with an Ubuntu 19.10 guest (the easiest solution ; with all the drawbacks of virtual machines)
1 Like

well it was tried, I will look for other methods to see how to install it, however I will also look for another library that will help me

I recently added an “invoke” task to compile ngspice due to the lack of libngspice on Ubuntu Travis CI. To be documented …

pip install invoke
inv -l

inv ngspice.install