Trying To Debug A Python File

  • Thread starter Thread starter Hornbein
  • Start date Start date
AI Thread Summary
The discussion revolves around issues with Anaconda and Spyder installations, specifically the inability to view error messages due to the program window closing too quickly after an error occurs. Users suggest various troubleshooting steps, including checking for disk space, permission issues, and potential conflicts with existing Python installations. Recommendations include using the command prompt to run scripts, adding an input prompt at the end of scripts to keep the window open, and utilizing Spyder's internal console for error logging. One participant notes that their issues resolved unexpectedly, while another expresses frustration with persistent problems and the need for a new computer to resolve installation failures. Overall, the conversation highlights common challenges with Anaconda and offers practical solutions for managing error visibility in Python scripts.
Hornbein
Gold Member
Messages
3,395
Reaction score
2,759
The Anacoda/Spyder installation having failed, I'm running files from the Python prompt. Everything is OK except for one thing. When the program exits on a error the error messages are only visible for a few seconds. Then the window closes, destroying the message. How can I get Python to leave those messages up until I'm done with them?
 
Technology news on Phys.org
Why did the anaconda install fail? Are you short of disk or memory space? Are there permission issues?

Ive never had that happen to me. It seems fixing this will resolve many future issues.

What OS are you running on? Are you using pycharm or vs code editor?
 
jedishrfu said:
Why did the anaconda install fail? Are you short of disk or memory space? Are there permission issues?

Ive never had that happen to me. It seems fixing this will resolve many future issues.

What OS are you running on? Are you using pycharm or vs code editor?
Spyder comes up, I can edit files, but execution of said file leads to an infinite loop of "Restarting kernel." I went on line and found a debugging session for this error that went on and on. It was discouraging.

I have a 2024 model computer with plenty of memory and disk space. Someone said they had luck installing it as administrator. I tried that, didn't help. Running under Windows 11. All I do with Anaconda is run Spyder and Python through it. I installed Anaconda on my now-dead previous computer, no problems. I got tired of trying to get it to work and intead use Notepad to edit and run Python from its prompt. It works pretty well, except for throwing away the error messages sooner than I would like. My need is short term, I'm not going to be a long-time user.
 
Im sorry youre having these issues. In general, anaconda installs quite easily and just works.

The only thing I can think of is something in your environment is messed up like the wrong python exe is being called or the lib paths have duplicate named libs or dlls in the path. Things like that.

It's especially frustrating that the error msgs appear and disappear so quickly. Maybe you could rerun and use your phone to screen shot the screen or take a video of the process.

From there you can search on the error message captured. You could try to get a keybd initiated screenshot but it may be too fast to capture. The video might be the best strategy though.
 
Last edited:
Have you tried adding this line at the end of your script?

Python:
input("Press Enter to exit...")

It might hold the window open for you to retrieve the message.
 
Some more ideas I found online for you to try:

Spyder has an internal console for errors related to Spyder itself:

  • Go to View > Panes > Internal Console and enable it.
  • Also check Tools > Preferences > IPython Console > Advanced Settings for logs.

Alternatively, use try/except to catch and log errors:
Python:
try:

    # your code here

except Exception as e:
    print("An error occurred:", e)
    input("Press Enter to exit...")

Try launching Spyder from Anaconda Navigator, so any error dialogs may also appear in the navigator logs.

I’ve not tried any of these personally and haven't used Anaconda since 2021. When I did it was on a Linux or WSL session on Windows 11.

Good luck. I feel its got to be something simple.
 
Last edited:
jedishrfu said:
How did things go?
I spent hours trying to get Spyder to work, no luck. I enlisted ChatGPT who had good ideas but no success. I believe if I want to get it to work I'd have to buy another computer.

The disappearing tracebacks went away by themselves somehow, so Notepad + command line Python is OK. We tried to install the gamepy library but no dice. Same mysterious problems having to with "file already there" even though I just deleted it, then "file not there" even though it is.
 
Something is wrong. I can't help but feel that another Python installation is interfering with your Anaconda distro.

I've never had that happen before.

I'm at a loss for how to proceed. Wrt to the file, it seems you may have a similarly named file accessible by python or that python is not running in the directory you think its running in.
 
Last edited:
  • #10
jedishrfu said:
Have you tried adding this line at the end of your script?
Python:
input("Press Enter to exit...")
Here's something else you might try. If you're running your Python scripts by clicking on them in Explorer, the script will open its own window, and then close it when the script finishes. In contrast if you already have a command prompt window open, and type "python program.py" (with program.py being the name of your script) the window shouldn't close when the program is finished.
This is more or less the way things work in C or C++ if you try to double-click the .exe file in Explorer. I haven't done any Python coding in a couple of years, but when I did, I didn't use any special GUI -- I just wrote the code using an ordinary text editor, and ran the code out of a command prompt window exactly as I described above.
 
  • #11
Add this to the end of the script:
[CODE lang="python" title="Python"]input("Press Enter to exit...")[/CODE]
Or run the script from an open command prompt instead of double clicking:
Bash:
python your_script.py
That way, the window stays open and the error messages won’t disappear right away. Another trick...run it like this:
Bash:
python -i your_script.py
That leaves the python prompt open after the script runs, so stuff doesn’t vanish on exit. It's pretty handy for checking what went wrong.
 
  • #12
Mark44 said:
Here's something else you might try. If you're running your Python scripts by clicking on them in Explorer, the script will open its own window, and then close it when the script finishes. In contrast if you already have a command prompt window open, and type "python program.py" (with program.py being the name of your script) the window shouldn't close when the program is finished.
This is more or less the way things work in C or C++ if you try to double-click the .exe file in Explorer. I haven't done any Python coding in a couple of years, but when I did, I didn't use any special GUI -- I just wrote the code using an ordinary text editor, and ran the code out of a command prompt window exactly as I described above.
Aha. The problem went away and I didn't know why. I think this was it.
 

Similar threads

Back
Top