(Python, IDLE, Windows) Pressing Stack Viewer exits all IDLE windows - python

I am running Python 3.1.2 with IDLE 3.1.2 on Windows 7. When I try to use the Stack Viewer, blue text and a new window briefly appear before all open IDLE windows exit (I don't have time to read the text or new window). This is the first time I have used Stack Viewer.
Is this normal behavior? How can I get the Stack Viewer to stay open?
Thanks for your help,
Alex

This IDLE bug (3 series only) was fixed 30Jan11. The fix is in 3.1.4 and 3.2.

From the documentation, the stack viewer shows the stack traceback of the last exception. So maybe in your case, you are trying to open the stack viewer, without any exception haven taken place?
>>> a
Traceback (most recent call last):
File "<pyshell#30>", line 1, in <module>
a
NameError: name 'a' is not defined
If you type 'a' and press ENTER, an exception occurs. Now try opening the stack viewer?

I don't have Windows so I can't help you with hands-on experience, but I would do the following:
see what is the exact command that runs when you click on the menu item for Idle (I think you can right-click and see its properties, or at least you could on earlier versions of Windows)
open a command prompt, and run the command that opens Idle
open the stack viewer and then note the traceback that (should!) appear in the command prompt window
report said traceback here :)
BTW, in my installation (neither Windows nor Python 3.x), an attempt to open the stack viewer without a traceback produces the following message box:
Title: No stack trace
Message: There is no stack trace yet.
(sys.last_traceback is not defined)

Related

Vs code doesn't regognize tkinter on pop os

I have a code, where i use tkinter to make a window and stuff. It's a brawler picker for brawl stars. Im using pop os-linux and vs code and i have tried so many ways, but anything doesn't work.
When i run the code, i get this:
(.venv) sh-5.1$ python -u "/home/"my_name"/Documents/Vs-code_projektit/Joku.py"
Traceback (most recent call last):
File "/home/"my_name"/Documents/Vs-code_projektit/Joku.py", line 2, in <module>
from tkinter import *
ModuleNotFoundError: No module named 'tkinter'
And in the vs code itself, it regognizes the tkinter and turns the text green, but after that nothing relating to tkinter doesn't work and i shows an error. Btw i have the full code already cause i copied from my dual boot windows and i wanted to try it here,
What should i do to make it work?
EDIT:
For everybody who has the same problem, it may be caused by the app version. I posted this on reddit cause i didn't get answer in time, and someone suggested that i download vs code with appimage, snap, or in my case pop!_os Installation.
MAIN POINT: Someone said that NEVER use FLATPACK with ides. It may work for other apps but never use it with ides. It can't handle system packages or modules.
First of all, you need to know what interpreter is currently used by vscode, which is displayed in the lower right corner of the interface.
Clicking on the displayed python version will open a Select Interpreter panel where you can select the interpreter with the tkinter package installed to run the code
Or you can install the tkinter package for the currently used interpreter.
<path-to-current-python.exe> -m pip install tkinter
EDIT
From your terminal information it can be seen that you have activated the virtual environment, but you are running the code with Code Runner.
As a reminder, Code Runner doesn't change interpreters as you select another interpreter in the Select Interpreter panel. So please use the Run Pythonn File option provided by the official Python extension to run the code.

Windows console prompt doesn't show up after an unhandled exception

Feeling really stupid right now. I opened a python file in my Windows console and the file raised an error (such as TypeError, AttributeError, etc.) and the console won't work anymore so I have to close it and open a new window everytime I get an error. There should be a shortcut or something to exit but Ctrl+C doesn't work. I have Windows 10 and Python 3.6.
When I run my file in the console happens this:
C:\Users\...path...>python my_file.py
Traceback (most recent call last):
File "C:\Users\...path...\my_file.py", line 74,
...stuff...
AttributeError: my error
And after this I can't do anything. If someone could help.
On an unhandled exception, a Python program normally quits, and you get the console prompt back. If yours doesn't, it means that it hangs instead.
If Ctrl-C doesn't work, you can force-kill a Windows console program with Ctrl-Break.
But you really should find out why it hangs, as it's not normal. My guess is you're swallowing all exceptions somewhere, e.g. with an unqualified except: which is strongly discouraged exactly for this reason.
May be because of bug/error your program become freeze. Please try to use exception handling.
An example :
try:
your_codes()
except Exception as ex:
print(ex)
This is just an example of exception handling. You can do it in much better (but complicated!) approach.
You can read this doc.

have ipython open editor at an error in a script

When running a script in Ipython (with %run) and there is an error in the script, is it possible to open an editor at the line of the error or have an open editor jump to that line?
Automatically this is not happening, although one could implement something like that. The question is, what would be the correct file to open? The backtrace will reveal all possible files in which the functions raised the error. In a large project, it would not be clear in which file the error is, is it with the caller or callee who made the error?
Most advanced IDEs e.g. eclipse with pydev allow direct jumps to the lines and function calls, so it is covered there.
on an ipython level you could do
%edit file_named_in_error.py

How to get file and line number links in tracebacks in PyCharm with remote interpreter?

When I'm using a local interpreter and there's an exception or error thrown during execution of a python program, there are links to the files and line numbers in the stack trace that's printed in the run window. When I'm using a remote interpreter (via Vagrant in this case), they're not there. Is this a missing feature or have I configured PyCharm incorrectly?
Edit: I should add that this is with PyCharm 3.1.1
This feature was added in PyCharm 4.0. https://youtrack.jetbrains.com/issue/PY-10224

PyDev: Fatal error Python32\lib\io.py, line 60, in <module>

I work in PyDev and quite suddenly, I cannot run my python programs from within Eclipse's PyDev (version 2.1.0) anymore.
Any python program I have ran through Run As > Python Run fails wioth
Fatal Python error: Py_Initialize: can't initialize sys standard streams
Traceback (most recent call last):
File "C:\Python32\lib\io.py", line 60, in <module>
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
I can still run my program in command Line, only Eclipse * I have only one version of Python (3.2)
I haven't changed my python files since last time they worked. They are encoded UTF-8.
I haven't upgraded Eclipse nor PyDev since last time they worked
Python is installed in c:\python32 (defined in the environment variable PYTHONPATH)
My XP system has been updated today for KB2536276 and
Any idea?
I have finally found out where the problem came from: I had a file called stat.py and this is apparently creating a conflict with Lib/stat.py
Unfortunately the error message was very obscure.
And I just don't understand why pyDev behaves differently than python.exe

Categories