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.
Related
I was making a program using pywhatkit to send WhatsApp messages. However, when trying to import pywhatkit, the following exception is raised:
(Sorry, I was not able to copy the error message.)
Can anyone tell me why this is happening?
One of the dependencies of pywhatkit is the pyautogui module (see here for what pyautogui is). REPL.it runs on Linux, a Unix-like OS; on Unix, pyautogui requires Xlib (hence, Xlib.error.XauthError). On importing pywhatkit, Xlib attempted to open the .Xauthority file, but failed to do so, in this case because the file does not exist. I believe this behavior has to do with REPL.it itself, i.e., there's nothing you can do about it.
For background on what the .Xauthority file is, refer to this AskUbuntu question.
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'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
I am fairly new to programming in python. I installed anaconda and am running iPython (the Jupyter qtconsole) v.4.3.0 and python v.3.6 on a Mac. Currently, I am trying to import a module with functions located in my home directory.
I have looked at stackoverflow and python documentation and found that it could be done with:
%run "Users/myUser/python_functions.py"
or
import python_functions
However, when I try both of these approaches, I get prompted to overwrite the file that I am running or importing:
File `python_functions.py` exists. Overwrite (y/[N])?
This is changing the previous file and not getting the functions I want to be imported.
What may explain this, and what can I do to import my module?
this is wrong but leaving it up for shame
import on ubuntu (and I'm guessing many other unix-like OSs including Mac) is a utility that saves any visible window on an X server and outputs it as an image file. You can capture a single window, the entire screen, or any rectangular portion of the screen.
My guess if you are running the import command in your console, and it's about to take a screenshot and save it over an existing file - python_functions
Before you the use the python import command, start a python interpreter:
$ python
>>>import yourfile
edit: on re-reading your question, I'm not so sure about my guess anymore, but leaving it up until you tell me I'm wrong :)
Running Jupyter qtconsole as an interpreter is likely causing the problem in this scenario. Instead using a IDE or command line interpreter will resolve it .
Since anaconda was installed, trying it with the IDE Spyder executes the code just fine without the overwrite prompt. It works on others (e.g PyCharm, Rodeo, etc.) as well.
I've recently started to use Python, and I don't know much about programming.
I've installed Python 3.4.3 in my Mac OS X Yosemite, and it worked fine for a few months, but now every time I want to run a module it stops responding.
so I use IDLE and when I open a new file to define a function I can write, then I click run and I save my file, and then when I click save IDLE doesn't restart as it use to and I can't write on it or do anything else. there is no crash report, no nothing, just all frozen. I close it and if then I re open and write on IDLE it works but as soon as I try to run a new file again it freezes.
How can I solve it?
to try stuff out i've been using repl.it online and it is useful for a learner like me but still I would like to be able to use IDLE on my mac.
THANK YOU FOR YOUR HELP!!!!
Try using Anaconda, which is another Python distribution, but more science-oriented. It has all the commonly required modules already in it (plus other for scientific purposes), so that you don't have to install them as and when required. And when you install Anaconda, it automatically installs Spyder, which is a much better IDE than IDLE.