Operating system:Win10
Slicer version:4.11.0(2020.6.15)
Expected behavior:The saveLabel.py should be run when I run C:\ProgramData\NA-MIC\Slicer 4.11.0-2020-06-15>Slicer.exe --python--script C:\Users\310091560\Desktop\saveLabel.py in the command line window.
Actual behavior: nothing happened except the Slicer main window(python interactor) openning.
Is this command line C:\ProgramData\NA-MIC\Slicer 4.11.0-2020-06-15>Slicer.exe --python--script C:\Users\310091560\Desktop\saveLabel.py right to run a python script?
Thanks in advance.
BTW, is the tutorial “[Documentation/Nightly/Extensions/DebuggingTools - Slicer Wiki](http://Visual Python debugging in PyCharm)” updated according to the 4.11 version? I cannot find the Python debugger extension and the “Python debugger” module (in “Developer Tools” category).
Thanks again.
I am trying to run a python script from Slicer 5.3.0 version on Ubuntu 22.04 OS. When I run it from the terminal like this:
./Slicer --python-script /home/username/ls.py
it gives this error eventhough I have tkinter on my system:
/lib/python3.9/ls.py
Switch to module: “Welcome”
Loading Slicer RC file [/home/gokce/.slicerrc.py]
:1: DeprecationWarning: The symbol module is deprecated and will be removed in future versions of Python
NOTE: You must install tkinter on Linux to use MouseInfo. Run the following: sudo apt-get install python3-tk python3-dev
Switch to module: “”
Switch to module: “”
When I put the ls.py script inside the folder: /home/username/Slicer-5.3.0-2023-07-29-linux-amd64/lib/Python/lib/python3.9/ folder and start the slicer and import the ls script from the python console and call a function from the ls script it gives this error:
>>> import ls
>>> ls.start()
File "<console>", line 1
import ls
^
SyntaxError: multiple statements found while compiling a single statement
>>>
Slicer uses its own virtual Python environment (you don’t need to install Python in your system). If you want to install a package in Sicer’s virtual Python environment then you can use the pip_install convenience function in the Slicer Python console.
SyntaxError: multiple statements found while compiling a single statement error means that statements are not separated by newline or semicolon (;). Maybe during copy-paste, the newline character gets replaced by a space? You may try to copy-paste from a different software or add semicolon after each statement (import ls; ls.start()).
I would not recommend to put any files into the Python library folder (/home/username/Slicer-5.3.0-2023-07-29-linux-amd64/lib/Python/lib/python3.9/). Instead you can put it anywhere and run it by calling as you did (./Slicer --python-script /home/username/ls.py). You can ignore the deprecation warning. When Slicer will upgrade to a Python version that does not contain tkinter anymore (or even before that) you can switch to Qt, which is already bundled with Slicer.
Dear Mr. Lasso, thanks a lot for the detailed and fast response. When I run it from the terminal like this:
./Slicer --python-script ../ls.py
Switch to module: "Welcome"
Loading Slicer RC file [/home/gokce/.slicerrc.py]
<string>:1: DeprecationWarning: The symbol module is deprecated and will be removed in future versions of Python
NOTE: You must install tkinter on Linux to use MouseInfo. Run the following: sudo apt-get install python3-tk python3-dev
Switch to module: ""
Switch to module: ""
I forgot to add that the slicer is opening for a second and closing itself. The ls.py script is using lung segmenter plugin in slicer and the same code is working on Windows. I want to run it on Ubuntu 22.04.2, I do not know what is wrong. I have tried many possible solutions that I have found on web. When I call the code from the python console without space like this:
I have tried to comment out one of my python package “pyautogui” and uninstall it from the Slicer, then my code worked. I wanted to take screenshots of the segmentation for each data with pyautogui. Do you have any suggestion for collecting the screenshots for each data?