Error launching Python IDLE via Crostini Terminal tkinter.TclError - linux

I recently got a Lenovo Duet Chromebook and had started using the Linux terminal to install Python and was using the IDLE Shell to run some basic commands. This was working fine until today, and now IDLE is failing to launch.
If I launch IDLE from the app drawer, then it pops up, but then instantly closes.
Running from the Terminal, I get the following error:
X Error of failed request: BadDrawable (invalid Pixmap or Window parameter)
Major opcode of failed request: 55 (X_CreateGC)
Resource id in failed request: 0x40004a
Serial number of failed request: 1142
Current serial number in output stream: 1152
If I try to launch again, I get a slightly different error:
Traceback (most recent call last):
File "/usr/bin/idle", line 5, in <module> main()
File "/usr/lib/python3.9/idlelib/pyshell.py", line 1483, in main root = Tk(className="Idle")
File "/usr/lib/python3.9/tkinter/init.py", line 2270, in init self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":0"
I've tried turning off Linux and back on, and installing the packages again. I tried a powerwash as well, but after installing everything I still get the same error.

The first error is coming from a call in the X11 client library, XCreateGC(), or rather it is coming from the Xserver as it is processing the message. That's how such calls error out, and it is really rare! (I'd love to know what caused it; it's really not supposed to happen. If it is difficult to hunt down what caused it the problem in the first place, fixing it is even more difficult.)
The subsequent messages are about failing to connect to the Xserver at all, almost as if it has crashed. Which is very odd! If the Xserver has crashed, it needs to be restarted before you can connect to it again. That in turn might require some effort to rebuild session credentials. (It's possible that the easiest thing to do is to just reboot.)
Tk (and hence, by extension, tkinter) doesn't talk to other ways of rendering to the screen on ordinary Unix, mainly because nobody has ever contributed an alternate mechanism. Such alternates exist for some Unix derivatives such as macOS and Android, but to my knowledge nobody's done Wayland yet. I could be wrong.

I have almost the same error.
Python 3.9.2 installed (regular deb packages) on Linux environment (Crostini?) running on Asus Chromebook with up to date system.
I'm able to run 'regular' X11 applications like gimp (xeyes and xlogo work as well), but there are issues with python's tkinter.
Trivial program like:
import tkinter
tkinter.Tk()
displays empty window as expected, but more complex tkinter apps fail.
Running IDLE produces:
wintermute#penguin:~$ idle
Traceback (most recent call last):
File "/usr/bin/idle", line 5, in <module>
main()
File "/usr/lib/python3.9/idlelib/pyshell.py", line 1483, in main
root = Tk(className="Idle")
File "/usr/lib/python3.9/tkinter/__init__.py", line 2270, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":0"
wintermute#penguin:~$

Issue has been resolved by a ChromeOS update, details here: https://bugs.chromium.org/p/chromium/issues/detail?id=1314921

Related

pygame.error: The video driver did not add any displays

I'm trying to get Pygame running on my Mac OS Monterey. The library installs fine and ends up where it should be. I've written a number of functioning programs with Pygame on my Linux machine and am using them as tests. The problem from what I can gather is that pygame.display can't be initialized for some reason. Every time I run a Pygame program it fails on the call to pygame.display.set_mode().
I am primarily using a wack-a-mole clone for testing. Here is the error I get:
pygame 2.0.1 (SDL 2.0.14, Python 3.8.2) Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last): File "mole_attack.py", line 34, in <module>
WINDOWSURFACE = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)
pygame.error: The video driver did not add any displays
Please let me know if anyone needs more info. I tried to be as detailed as possible. Thanks in advance for any help.
The problem was that the latest version of Pygame was 2.1.2 and I was using 2.1.0 which I thought was the latest. I updated Pygame and everything worked fine. I couldn’t find anything definitive on what changed between these versions and why this error existed to begin with. I’ll keep looking and see what I can find out.

Curses giving error when running curses.initscr() - python

Background:
I recently installed curses with pip install curses
I found a couple tutorials online (https://www.devdungeon.com/content/curses-programming-python, https://docs.python.org/3/howto/curses.html, https://www.youtube.com/watch?v=rbasThWVb-c)
I always constantly testrun my code when I install a new package or learn something new
Whenever I run s = curses.initscr() in IDLE, I get this error message:
File "C:/Users/jacob/AppData/Local/Programs/Python/Python37-32/screentest.py", line 3, in <module>
s = curses.initscr()
File "C:\Users\jacob\AppData\Local\Programs\Python\Python37-32\lib\curses\__init__.py", line 30, in initscr
fd=_sys.__stdout__.fileno())
AttributeError: 'NoneType' object has no attribute 'fileno'
This is the message from PyCharm:
Redirection is not supported.
Process finished with exit code 1
And when I run a sample snippet from DevDungeon,
print("Preparing to initialize screen...")
screen = curses.initscr()
print("Screen initialized.")
screen.refresh()
curses.napms(2000)
curses.endwin()
print("Window ended.")
in command prompt with python booted, it just gives an uninteractable blank screen.
Is the thing happening in shell correct?
What the hell is going on?
How can I fix this?
please help thank you
sys.__stdout__ is the original sys.stdout for a python process. When you start python with pythonw.exe, which only exists on Windows, python initially executes stdout = __stdout__ = None. (I am not sure about what happens on *nix.) pythonw.exe is used to run python with a GUI UI without an associated text console. On Windows, the IDLE icons and Start menu entries run python with pythonw. Same with other GUI IDEs.
curses runs with text terminals or consoles. It assumes that sys.__stdout__ is such. It cannot work when sys.__stdout__ is None.
If you start IDLE from a command line terminal/console with python -m idlelib, sys.__stdout__ will be that terminal, and it will have a fileno(). What will happen after that I do not know. If your program uses curses, you are likely better off to run it in the text console.

OSError: [Errno 8] Exec format error using ChromeDriver with Selenium and Linux on Raspberry Pi

Im trying to access and interact with a website using selenium and the chrome driver. I downloaded the chrome driver from here,
specifically I downloaded version 2.45 and the linux64 version because I'm on raspberry pi. I also installed geckodriver the arm version for linux. I unzipped both of these files and moved them to my /usr/bin folder because that is where my python 3 path is. Here is my code:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://www.google.com")
I run this code and the error message I get is
Traceback (most recent call last):
File "/home/pi/test with selenium.py", line 2, in <module>
driver = webdriver.Chrome()
File "/home/pi/.local/lib/python3.5/site-
packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/home/pi/.local/lib/python3.5/site-
packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/usr/lib/python3.5/subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1282, in _execute_child
raise child_exception_type(errno_num, err_msg)
OSError: [Errno 8] Exec format error
I checked to make sure chromedriver is an executable file and it is, I know this from looking under properties and permissions and it says anyone can execute the file. I tried installing homebrew (I'm not sure if I did it right) and running brew install chromedriver, still didn't work. Another solution I read online thought I had the wrong chromedriver file for my operation system, but I am pretty sure I do. This is my first time using selenium, so hopefully, I'm not doing it completely wrong. Any help is appreciated!
I finally managed to get chromedriver to work on raspberry pi! The first thing I was doing wrong was using the latest version of chromedriver (version 2.45) which only works for Chrome versions 70-72. Currently (December 2018) the highest version of Chromium (open source Chrome) available on raspberry pi is 65 (source). So that meant that chromedriver versions 2.36 - 2.38 SHOULD work, yet they didn't. Why they still gave me that OS Error, I still don't understand. However I found a useful reddit post (yes, reddit) which I will link here. Basically, instead of downloading chromedriver from their offical website I needed to download it from here. This website has chromedriver for arm, rather than just linux 64 bit. So I clicked on chromedriver 65 in armhf (updates), and downloaded the .deb file seen on the right side of the page. Then I opened it by double clicking and my raspberry pi unzipped the .deb file and gave me a file named chromedriver located in /usr/lib/chromium-browser. I ran
sudo mv /usr/lib/chromium-browser/chromedriver /usr/bin in terminal to move the chromedriver file to my python directory. Now this piece of selenium code worked perfectly in python and on raspberry pi:
from selenium import webdriver
driver = webdriver.Chrome()
Again, I wouldn't have solved this without the helpful reddit post I will link again here. All of the steps I described above are described in the reddit post, I'm just trying to get the word out!
This error message...
OSError: [Errno 8] Exec format error
...implies that the ChromeDriver binary which was invoked was not in proper format.
Your main issue is the incompatibility of the ChromeDriver binary format with respect to the underlying Operating System.
As you are on linux64 bit version on Raspberry Pi you need to download chromedriver_linux64.tar.gz from chromedriver.storage.googleapis.com, untar it and provide the absolute path of the GeckoDriver through the argument executable_path as follows:
from selenium import webdriver
browser= webdriver.Chrome(executable_path='/path/to/chromedriver')
Additional Consideration
Perform the additional clean up tasks:
ChromeDriver is present in the specified location.
ChromeDriver is having executable permission for non-root users.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
(WindowsOS only) Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
(LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint before and after the execution of your Test Suite.
Take a System Reboot.
Execute your Test as a non-root user.
Google's chromedriver_linux64.zip contains an amd64/x86-64 binary only, which is the root issue here.
For Raspberry Pi users: Pre-built ARM64 linux chromedriver binaries that will work on Raspberry Pi and others are available in most Electron releases. Hopefully this helps.
I took a driver from one of my old projects.
And I was getting the same error.
It turns out that I was trying to run windows chrome driver in Linux.
Dumb me!

"thread panicked while processing panic. aborting" error while executing test through GeckoDriver Firefox and Selenium

I am new to coding and web scraping. However I already encountered error while just tried to open a url with browser by simply code.
Source code
import sys
import urllib.request
import importlib
import time
from bs4 import BeautifulSoup
from selenium import webdriver
importlib.reload(sys)
url = 'http://www.python.org'
driver = webdriver.Firefox()
driver.get(url)
browser.close()
Result:
Traceback (most recent call last):
File "D:/Documents and Settings/Administrator/桌面/Old Data/WS/111.py", line 9, in <module>
driver = webdriver.Firefox()
File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 157, in __init__
self.service.start()
File "C:\Python34\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
self.assert_process_still_running()
File "C:\Python34\lib\site-packages\selenium\webdriver\common\service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 3221225501
Here is the log of Geckodriver
1533786140718 geckodriver INFO geckodriver 0.21.0 (c7d3022be6420de1ca4076d932aa32b299f3ea10 2018-06-14)
thread panicked while processing panic. aborting.
1533786140734 geckodriver INFO Listening on 127.0.0.1:2472
thread panicked while processing panic. aborting.
This error message...
Traceback (most recent call last):
File "D:/Documents and Settings/Administrator/??/Old Data/WS/111.py", line 9, in <module>
.
selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 3221225501
...implies that the GeckoDriver was unable to initiate/spawn a new WebBrowser i.e. Firefox Browser session.
You need to take care of a couple of issues as follows:
As per your code block importing sys, urllib.request, importlib and time was unnecessary, so you can remove them.
From the error trace log it is evident you are executing your #Test as an Administrator which must be avoided. Always execute your #Test as a non-root user.
You are possibly using Windows XP as the underlying OS.
Always invoke driver.quit() method to close & destroy the WebDriver and Web Client instances gracefully.
thread panicked while processing panic, Rust, Panic and WinXP
As per the release notes of GeckoDriver v0.11.0 of 2016-10-10:
Changed Rust compiler version to 1.12 (beta) temporarily because of trouble linking Musl binaries
Replaced env_logger logging facility with the slog package, causing the RUST_LOG environment variable to no longer have any affect.
Updated the WebDriver Rust library to version 0.15
Moving forward as per the release notes of GeckoDriver v0.14.0 of 2017-01-31:
Stacktraces are now included when the error originates from within the Rust stack.
Now in Windows XP doesn't have ConditionVariables, which notify requires via mpsc channels #retep998 mentioned:
Windows XP support is super shady. While libstd does not link to any functions that are unavailable on Windows XP, certain std functionality does load those functions at runtime and will panic if they don't exist. It's quite likely that somewhere rsnotify depends on some functionality that requires an API that isn't available on Windows XP.
But it seems as per Panic broken on Windows XP #alexcrichton mentioned:
When a thread panics it attempts to run its panic hook, but that panic hook is protected by an RwLock which is in turn not implemented on XP. That means that when panicking you'll panic immediately as you attempt to acquire an rwlock.
Finally, MUSL target doesn't link on nightly seems to get resolved in rustc 1.12.0-nightly (a005b6785 2016-08-02)
Conclusion
With the current releases of Selenium v3.14.0, GeckoDriver v0.21.0 and Firefox v61.0.2 execute your #Tests as a non-root user on non WinXP OS (e.g. Win7, Win8 or Win10) which will solve your issue.

py2app builds ok but app fails with "_tkinter.TclError" (and no error message!)

I am using py2app 0.9 on Mac OSX Yosemite 10.10.1 running Python 3.4 from the anaconda distribution and with Tcl 8.5.
In earlier attempts, the build would fail, but quick searches revealed solutions to these problems (i.e. including 'packages': ['tkinter', 'matplotlib'] in OPTIONS in setup.py, and changing line 49 of MachOGraph.py: loader --> loader_path)
Now py2app finishes the build, and running in Alias mode my app functions, but when I build in normal mode (python setup.py py2app) the resulting app will not open and the console shows the following traceback:
Traceback (most recent call last): File
"/Users/ryankeenan/Desktop/fishing/gui_test/dist/deani.app/Contents/Resources/boot.py",
line 355, in _run() File
"/Users/ryankeenan/Desktop/fishing/gui_test/dist/deani.app/Contents/Resources/boot.py",
line 336, in _run exec(compile(source, path, 'exec'), globals(),
globals()) File
"/Users/ryankeenan/Desktop/fishing/gui_test/dist/deani.app/Contents/Resources/deani.py",
line 731, in app = fishingapp() File
"/Users/ryankeenan/Desktop/fishing/gui_test/dist/deani.app/Contents/Resources/deani.py",
line 536, in init tk.Tk.init(self, *args, **kwargs) File
"/Users/ryankeenan/Desktop/fishing/gui_test/dist/deani.app/Contents/Resources/lib/python3.4/tkinter/init.py",
line 1851, in init self.tk = _tkinter.create(screenName, baseName,
className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError
The frustrating thing is that it doesn't print any error message for "_tkinter.TclError". I've searched quite a bit and failed to find any solutions or replications of this problem. I've tried building various tkinter based apps and they all fail in the same way.
This is occurring at the first call to tk.Tk.init(self, *args, **kwargs) in my code.
My setup.py file looks like this:
from setuptools import setup
APP = ['deani.py']
DATA_FILES = []
OPTIONS = {'packages': ['tkinter','matplotlib'],'argv_emulation': True}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'], )
I was having this problem and discovered that it was due to conflicting versions of tcl/tk in the /Library/Frameworks. Check the output of the build (make sure to delete the old build first) for references to different versions of tcl/tk. I found that my current version of tcl/tk was 8.6 which py2app was linking to, but at the same time py2app was copying files from tcl/tk 8.5. I solved the problem by removing 8.5 from `/Library/Frameworks/(Tcl/Tk).framework/Versions.
NOTE: I would not recommend removing a version unless you see the problem in the build output and know that nothing else (that you care about) depends on that version.
However, this was not my only error, because when I deleted the old version, I discovered a new _tkinter.Tcl error, which pointed to a bug in my code. If you want to view the traceback without having to go to console, I suggest placing a try/except statement around your starting code which prints the traceback to a file. For instance:
import sys, time, traceback
try:
run()#Your opening code goes here
except:
with open('/Path/to/somewhere/tb.txt','a') as file:
y,mn,d,h,m,s,a,b,c = time.localtime()
file.write("==================="+str(mn)+'/'+str(d)+' '+
str(h)+':'+str(m)+':'+str(s)+
"=====================\n")
traceback.print_exc(file=file)
Hope this helped.

Resources