nunobrum / PyLTSpice

Set of tools to interact with LTSpice. See README file for more information.
https://www.nunobrum.com/pyltspice.html
GNU General Public License v3.0
203 stars 59 forks source link

Could not run a simple simulation #131

Closed Z18Aplha closed 8 months ago

Z18Aplha commented 8 months ago

I have an issue running a simple Job from the Pyton Interface. I created a working *.asc File (in LTSpice everythin works fine) and tried to trigger the simulation from my python script.

The Script:

from PyLTSpice import SimRunner
from PyLTSpice import SpiceEditor

runner = SimRunner(output_folder="temp")
netlist = SpiceEditor('./model/BUCK-TL494.asc')

runner.run_now(netlist)

The Script throws an error regarding to the argument "WindowsPath" which is not iterable. Google shows that this could be problem with the file handling of Python - not necessarily of the PyLTSpice Package itself. I tried to debug, but i dont understand the problem and where it has its source. So i need your help.

The error:

Wed Feb 14 16:11:03 2024 info: RunTask #1:: Starting simulation 1

Exception in thread RunTask#1:
Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\threading.py", line 917, in _bootstrap_inner
    self.run()
  File "C:\Users\Aaron.WINKLER\AppData\Roaming\Python\Python37\site-packages\PyLTSpice\sim\run_task.py", line 101, in run
    self.retcode = self.simulator.run(self.netlist_file, self.switches, self.timeout)
  File "C:\Users\Aaron.WINKLER\AppData\Roaming\Python\Python37\site-packages\PyLTSpice\sim\ltspice_simulator.py", line 173, in run
    return run_function(cmd_run, timeout=timeout)
  File "C:\Users\Aaron.WINKLER\AppData\Roaming\Python\Python37\site-packages\PyLTSpice\sim\simulator.py", line 30, in run_function
    result = subprocess.run(command, timeout=timeout)
  File "C:\Program Files\Python37\lib\subprocess.py", line 472, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Program Files\Python37\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "C:\Program Files\Python37\lib\subprocess.py", line 1119, in _execute_child
    args = list2cmdline(args)
  File "C:\Program Files\Python37\lib\subprocess.py", line 530, in list2cmdline
    needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: argument of type 'WindowsPath' is not iterable

I am using: Python 3.7.2 PyLTSpice: 4.0.6 LTSpice: 17.1.8 (x64)

Thank you in advance! Z18Aplha

nunobrum commented 8 months ago

Yes.... by the look of it, it is a mismatch between the pathlib and the subprocess libraries that are being used. For some strange reason, the versions that I have on my installation don't seem to have this problem. As I understand from your error log, the subprocess needs to receive a string not a WindowPath from pathlib. I suggest two possibilities:

I hope this helps.

Best Regards, Nuno