How to fix pyspice OSError: cannot load library 'libngspice.so'
Problem:
When trying to run a PySpice program, you see an error message such as
pyspice_libngspice_error.txt
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'Solution
Install libngspice, often called libngspice0.
On Ubuntu, install it using
example.sh
sudo apt -y install libngspice0-devYou need to install the -dev library since libngspice0 only contains libngspice.so.0 whereas the -dev library contains libngspice.so which is required by pyspice.
Solution (with KiCad installed on Linux)
KiCad automatically installs libngspice-kicad which provides libngspice.so.0 but collides with libngspice0 and libngspice0-dev. To fix this, you can create a symlink:
example.sh
sudo ln -sf /usr/lib/x86_64-linux-gnu/libngspice.so.0 /usr/lib/x86_64-linux-gnu/libngspice.soAfter that, restart your Python script, which should work now.
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow