I'm working through Think Python chapter 4, where they tell you to type the following to see if you have the turtle module:
import turtle
bob = turtle.Turtle()
This is supposed to open a new window, but instead, it crashes my computer. I've seen it freeze my computer where I can't move the cursor or change windows, and I have to restart it. And I've also seen it close all my programs and re-open them.
I'm running Python 3.7 downloaded from Anaconda on a Macbook Air with Mojave version 10.14.6.
EDIT: When I run BenajahTX's suggestion below, I get this error message printed 16 times:
CGSTrackingRegionSetIsEnabled returned CG error 268435459
Any clue what is causing this or how to fix it?
try and set the screen and mainloop
window = turtle.Screen()
window.setup(width,height)
while True:
window.update()
window.mainloop()
Try running the file in the terminal using the command:-
$ python filename.py
I had the same issue and I was VS code extension Code Runner to run the python file, however, when I tried the terminal it worked and the mac OS was not crashing this time
Related
I have been using pycharm in my mac but while importing pygame, there is no window popping up. I have copied some codes from google about pygames but it is also not working. I think there might some settings problem in mac os because in my pc the code is working perfectly. Another information is that no error is showing, which means no problem with code or interpreter.
For me, and other people, Python 3.8 doesn't work with PyGame for some reason. Try using Python 3.7.
I am also using PyCharm...
I found, as a workaround, on Apple,
if your "Force Quit" the running Python in the Dock,
and then try to run it again you get:
Whichever one your choose, it then continues and displays the window.
I've been using tkinter in a python program that I've been working on, and up until today the program was running correctly, but now on running the program without changing any code my computer restarts after responding to the first tkinter window. Running python -m tkinter in the terminal also crashes.
I completely uninstalled and reinstalled anaconda (version 4.7.10)and python (version 3.7.3) and nothing has changed. This is on macOS 10.14.6.
The error message "Class FIFinderSyncExtensionHost is implemented in both ... and ... One of the two will be used. Which one is undefined." also displays when the program is run, but I'm not sure if this is a related issue.
MacOS 10.14.6 update causes my MacBook Air to restart when I execute the a Tkinter python script. Worked fine before that. Must be an Apple problem. Even the simplest of scripts causes a catastrophic crash/restart.
I have a rather small Pygame based python script and I just bought a Mac so I'm trying to run my script on here. Everything has been installed correctly (Checking by typing 'import Pygame') into python terminal as-well as running a basic hello world program. However, when I try running this script, IDLE gets brought to the front but nothing happens from there. (The script is supposed to pop-up a new window). Is this a problem with my installations or my code? (Code works on windows setup).
You could try to run the script again on a windows computer to see if you forgot to save some changes or if the file got corrupted somehow. You could also use bootcamp to install Windows on your mac since you could have one windows version on your mac for coding purposes and the regular mac OS for other stuff if you like.
you can execute it by left clicking in your script and select open with python launcher
Code in question:
from tkinter import *
root = Tk()
test_label = Label(root, text = "Hello")
test_label.pack()
root.mainloop()
I can only run this python code from the IDLE, if I run it any other way the window flashes on the screen and closes immediately. I've tried:
-adding an "input" line to keep it from closing
-running from the windows powershell
-compiling the code into an EXE with pyinstaller
and now I can't find any other suggestions. I tried making a simple 1-line program that just asks for input, and that works normally and stays open fine. The tkinter program works fine in IDLE but not any other circumstance.
What's happening here?
EDIT: If I run the program from the command line instead of windows 10 powershell, I get the following output:
Traceback (most recent call last):
File "C:\Users\Cam\Desktop\CSCI Notes\Programs\test.py", line 1, in
<module>
import tkinter
ImportError: No module named tkinter
However, the tkinter file is in the python library on my computer, and importing tkinter in python shell or IDLE works fine.
When I run python on command prompt, it shows python 2.7, so I changed tkinter to Tkinter and the program worked by importing the .py file
Using cmd:
Pyinstaller works(through canopy cmd prompt):
the first line is what I put into my IDLE's cmd prompt
Which populates the folder when executed:
And inside dist, I run test.exe which shows the window
NOTE: my system command prompt is using python 2.7 while the canopy(python environment) command prompt uses 3.5 with pyinstaller
Okay, I think I've solved this one! I read that windows can sometimes try to open .py files with python 2.7 instead, even if they're written in 3.6. I uninstalled python 2.7 from my computer, and now the file runs normally.
So for anybody having this problem, try to make sure your computer is opening python 3, not python 2.
I have also had this problem and as far as I can see no one has a proper solution.
The best I have found is putting -i before your filename. For example:
python -i yourfile.py
this will start the IDLE in the command line
This could also happen if you are using a modulo that isn't installed in your computer even if you have installed it using your IDLE. Try installing it with the command "pip install modulo" else try installing it manually.
I've tried installing PyGame and it just crashes with the window closing too fast to see the error when I import it. I've tried every package, using the installer or wheel file, but none have worked.
The code I have so far is thus:
import pygame
input()
The program does not wait for a key press and still just closes at execution.
I am aware there are similar questions already, but none of those solutions have seemed to work.
The issue is not with installation. If there is nothing in your program, the program will just open and close really quickly.
You can test out your pygame module this way.
On Windows, open up the Python command line interpreter. Run:
>>> import pygame
>>>
You should see just a blank >>> if it loaded correctly.
Same for Linux and OS X, but just type python in a terminal to run the interpreter.
If it gives an error, comment the error below and we can go from there.