When I open idle through the terminal, idle opens fine but as soon as I try to scroll over the idle window or make any slightly quick movements of the idle window, it immediately crashes with error:
Traceback (most recent call last):
File "/usr/local/bin/idle3", line 5, in <module>
main()
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/idlelib/pyshell.py", line 1552, in main
root.mainloop()
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 1283, in mainloop
self.tk.mainloop(n)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
I have tried the command brew reinstall python --with-tcl-tk with no luck. I only get the error Error: invalid option: --with-tcl-tk.
I have tried to uninstall and reinstall completely a few times with no luck. I am using Tk version 8.5.9, I have updated that with brew but it seems that python is still using the old version.
While I don't know what the cause is, I was able to find a solution.
In idlelib/editor.py
If, you comment-out line 149, IDLE stops crashing when you try to scroll.
149 text.bind('<MouseWheel>', self.mousescroll)
150 text.bind('<Button-4>', self.mousescroll)
151 text.bind('<Button-5>', self.mousescroll)
This needs to be changed to:
149 ##text.bind('<MouseWheel>', self.mousescroll) # Now IDLE should work
150 text.bind('<Button-4>', self.mousescroll)
151 text.bind('<Button-5>', self.mousescroll)
This also seems to not break anything, but does fix the issue.
You can find this file by running
>>> import idlelib.editor
>>> idlelib.editor
<module 'idlelib.editor' from '/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/idlelib/editor.py'>
>>>
Tested:
macOS Mojave 10.14.3
Python 3.7.2 (From brew install python)
Tcl/Tk (8.5.9)
Update
The problem was also corrected by reinstall python from python.org.
Previously I was using a brew installation, which seems to have introduced the problem.
I just today update my Macbook Air to Mojave and Python 3.7.1, the latter with the PSF python.org installer, which installs tcl/tk 8.6.8 and tkinter compiled to work with that. IDLE tests pass and IDLE runs normally as far as I manually tested. I strongly recommend you do the same. I cannot support any other installation.
In my opinion, https://www.python.org/download/mac/tcltk/ should be updated to call 8.5.9 'Not Recommended'. See the last section "How Python Chooses Which Tk Library To Use" on how to get Python to recognize a newer 8.5.x
Apparently, there are even issues with tk 8.6.8 on Mojave. The Mac tk developer just wrote on the Python tracker today that there are changes in tk tip to accommodate Mojave API changes. 8.5 is no longer being updated.
Related
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.
Getting the following code opening in the console in 9 separate screens when I try to open Python IDLE. As far as I'm aware, there isn't anything that I have done to the original install. Any ideas? Tried uninstalling and reinstalling but no luck. The code shown when I open the program is...
try:
import idlelib.PyShell
except ImportError:
# IDLE is not installed, but maybe PyShell is on sys.path:
try:
from . import PyShell
except ImportError:
raise
else:
import os
idledir = os.path.dirname(os.path.abspath(PyShell.__file__))
if idledir != os.getcwd():
# We're not in the IDLE directory, help the subprocess find run.py
pypath = os.environ.get('PYTHONPATH', '')
if pypath:
os.environ['PYTHONPATH'] = pypath + ':' + idledir
else:
os.environ['PYTHONPATH'] = idledir
PyShell.main()
else:
idlelib.PyShell.main()
I only have the option to close this window and not to create a new Python file.
I am an Idle maintainer and it is very unclear how you tried to open Idle, what you mean by '9 screens', and what you 're-installed', and on what system and version of Python.
The easiest way to start Idle with installed Python is to use the Start menu icon (on Windows) or the equivalent on other systems. On a command line, use python -m idlelib, where python starts some version of installed 3.x. For uninstalled 3.x or 2.x, use idlelib.idle. From within Python, import idlelib.idle starts Idle.
If you have python 2.7 or 3.4 properly installed and running, so that python -m test.regrtest runs and passes (.regrtest is only needed for 2.x), I would be very surprised if Idle did not run with the methods above.
The code you posted is idlelib/idle.pyw. It is used by idlelib/idle.bat and may have other specialized uses, such as running Idle with a subprocess call. I suspect that it is partially obsolete. In any case, I doubt it will be helpful to you.
(I don't know if this is an appropriate question for StackOverflow, as it's about a tool rather than a language.)
My Python 3.3.1 (32-bit) command line ("C:\Python33\python.exe") has stopped accepting tab characters. It can print them, but pressing the Tab key just makes the cursor blink at me (it reacts, but doesn't move). It wasn't happening earlier today.
I also have 2.7 (32-bit) and 3.2 (64-bit) installed, and neither of them have this problem. Trying to run each of the python.exe executables from the same cmd.exe window gives the same result, so it's not due to the command line window settings. Running a .py file (">python my.py") doesn't have the problem. IDLE for 3.3 doesn't have the problem.
Also, when pasting text from the clipboard, they're read s l o w l y (takes about 15 seconds to read a hundred lines of 50-char commented lines, compared to less than a second on the others) and
The only change I remember making recently (since the last time I remember opening python.exe) was to install Scipy for 3.3 from http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack (32-bit).
No, I have not tried turning the computer off and on again. I hope not to. I haven't tried uninstalling and reinstalling Python 3.3, since that means reinstalling packages. Updating to 3.3.3 didn't solve the problem.
Try to remove the pyreadline directory in lib\site-packages. Scipy-stack includes pyreadline, which is required for the IPython terminal but also changes the behavior of the standard interactive prompt.
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
Recently I installed wxPython to do some works under Windows. Most of the time I work in Linux so I have a little experience here.
with python.exe interpreter, I just do 2 line of codeimport wxtmp=wx.App(False)
Then the interpreter crashed with Windows error reporting.
I tried both python 2.7.1 and 2.6.6 with wxPython 2.8.11, all come from their main website, still no luck.
Is there something I must do after install Python in Windows ? I can see that python install just fine and can do some basic job, wxPython library can be load, but can't call wx.App
If you are running that in IDLE, then that is your problem. IDLE and wx don't get along very well because you basically end up with two mainloops fighting each other. Try putting it in a file and then run the file from the command line:
c:\python27\python.exe myPyFile.py
That should work just fine. Otherwise, download the correct wxPython for your Python and OS (32/64 bit), uninstall the current one and install the new one. I've been using wxPython on Windows XP, Vista and 7 with no problems like this.
In case like me somebody will stumble into this question like I did. Recently installed wxpython on two machines, windows 7 and XP. Testing the sample code in simple.py (provided with the wxpython docs-demos installer), running from a python console, I had the following problem on both machines: First import ok, but when I did a reload of the module, python crash.
I added this line in the end of the simple.py file: del app
and that fixed the problem on windows 7 and tomorrow I try it on the XP machine.
Same solution fitted for the XP machine. So, reloading an un-edited module with a reference to a wx.App with a closed gui seem not to be feasable. Killing the reference with a del statement was enough to solve the problem.
I searched for a while and found that this is the problem with wxPython and Python >2.5. Tried many fix with manyfest file but no luck, so I think switch to PyQt is the only solution now.