Example transistor

good afternoon I communicate with the community because I am not very good at programming but I am trying to learn how to simulate circuits that I need for a job, however when I try to simulate the circuit of the example of transistors I get the following error

Traceback (most recent call last):
  File "polos.py", line 50, in <module>
  File "/usr/local/lib/python3.6/dist-packages/PySpice/Spice/Library.py", line 107, in __getitem__
    raise KeyError(name)
KeyError: '2n2222a'

It looks like you didn’t provide a spice model for the 2n2222a transistor. In general, spice models are mostly protected by copyrights so you shouldn’t expect to get models with PySpice or Ngspice (or really any other open source project for that matter). You can still find them online though. For instance, here’s a link to the model you want. That site contains tons of other useful models too. The other way I know to find them is to search the product vendor and spice. A bunch of MFGs provide spice models, but you have to download it from their site.

thank you very much I had no idea about that

The 2n2222a is actually provided in the PySpice example directory (PySpice/examples/libraries/transistor/2N2222A.lib) for demonstration purpose.

The only “trick” is to provide the path of the library directory in your own python script.

The example “PySpice/examples/transistor/transistor.py” works because the library path is generated using the PySpice standard location and provided through the commands :

libraries_path = find_libraries()
spice_library = SpiceLibrary(libraries_path)

In your case, you should provide SpiceLibrary(...) with the path of your library directory.
(Except if you exactly match the PySpice example directory architecture, you should always provide the path of your library directory. )

@huszaghmatt copyright issue is an important point to mention !

Does somebody know if we could implement a web downloader ??? What about Eagle ??? I have the feeling that on some points the electronic industry doesn’t help CAD design …

I’m intrigued by the idea of a spice model downloader. Finding spice models is a bit time-consuming and it’s a hurdle when you first get started with simulations.

One nice feature would be to store a cache of models and download urls so that someone using the downloader wouldn’t need to rescrape the sites or give the downloader hints about where to find the model. I imagine this would be permissible without violating copyright since we wouldn’t store the models. The cache does of course present some additional challenges. The repo would either need frequent PRs as the model locations change, or require supporting a server to perform the scrapes.

I also wonder if it’s worthwhile to do this as a separate project from PySpice, since other projects might be able to leverage this functionality without requiring the full-blown simulation capability of PySpice. Just a thought.

Infineon / IRF has https://www.infineon.com/cms/en/tools/solution-finder/product-finder/simulation-model/

but nothing is standardized ,nor library, nor Spice dialect

for generic part like 2n2222a we could make a repo similar to what Kicad do