This question already has answers here:
Problems getting pygame to show anything but a blank screen on Macos
(10 answers)
Closed 2 years ago.
Just started programming in python and pygames.
Whenever I try running a py file with pygames, the pygames window will appear, but there will be absolutely nothing in it. No errors in the log, but nothing shows, it's just a gray screen.
I tried running it on IDLE, and through the command line (I'm on a mac so I use the terminal)
And it's not just my programs that aren't showing anything, I've tried to run one of pygames examples, and it will still not display anything. For example, if I run the pygames alien example, the window will appear with a blank gray background. I'll hear the audio for the program, but no display.
Anything would help, I'm at a loss especially since no errors are showing in the log.
EDIT1:
I'm using Python 3 (and I really need to keep using Python 3)
EDIT2:
I'm using python 3.7. pygames version 1.9.4. The examples are with the pygames, they were downloaded together, so I assume it's for that version.
EDIT3:
ok, my OS is Mojave 10.14. I've tried starting the application by: opening the file, running it on IDLE, and running it through the command line, none have worked. python2 is installed, but when I run the pygame it's a python3 file
Known issue with Mojave - see their issue tracking: https://github.com/pygame/pygame/issues/555
You can also install new pygame using pip install pygame=2.0.0.dev6. This
worked in my case.
Related
I am trying to get started with Python, so I installed Python 3.8, from python.org (on Windows 10). I remembered to check the "Add to PATH" during the installation and I have confirmed that it has been added to path, as seen in the first image.
However, when I try to use any commands, whether it be python --version or python HelloWorld.py, nothing happens. I have tried both the traditional command line as well as Powershell. I have also tried replacing python with python3, the result is the same. As you can see in the second image, I get no errors, just a blank line. So it's not that it cannot find Python at all, it rather seems that something is wrong with the installation.
Have anyone else encountered this kind of behavior? I have tried re-installing Python as well as removing old installations.
Image 1: Python seems to be correctly added to PATH.
Image 2: Python fails to return any output. But also no error. Same thing happens with python HelloWorld.py.
Update 1 - Here is what I have tried so far:
Changing PATH to refer directly to exe file.
Using both Command Prompt and PowerShell.
Rebooting the PC.
Re-installing Python (including removing old versions).
Both the python and python3 command.
Update 2 - NameError: name 'python' is not defined
Update on the update: This was a wild goose chase. You are not supposed to be able to use that command in the interpreter, as described in this post.
So I tried to use the console from the python.exe file instead, and I got the following answer. However, from what I can find on it, it's normally a problem you encounter on elements of the code (like print()) and not on the python command...?
(image removed)
Update 3 - It works (kinda)
If I use the command py --version or py test.py it works. I have no clue why though...
After extensive research, I still cannot find an answer to my own question. But I have found a work around, which minimizes the consequences:
Instead of using python, simply use py.
This will invoke the Python launcher instead of Python itself (from what I've read). For most people this will be good enough, but it is not the same. So it might cause issues and version mismatch in certain scenarios.
Also, despite of this weird behavior, Python seems to run fine in Visual Studio Code, when using the "Run" button (or the py command in the terminal).
For some reason, whenever I try to open a python script that has around ~450 lines of code, IDLE's windows simply appears empty and when I try to run it doesn't run anything either... However, if I try to run a smaller program it works for some reason. Does anybody know how I am able to run a python script on my Mac besides IDLE or how to fix the IDLE window being blank whenever I open a file?
To learn how to run Python Python programs on a Mac, read Chapters 1 and 4 of Python Setup and Usage. Running from an IDLE editor is just one way.
IDLE uses the tkinter module which wraps the tcl/tk GUI framework. Did you read and follow the instructions of how to replace the buggy tcl/tk that Apple supplies? Read the entire page before starting! Ignoring this page is the most common reason people have problems with IDLE on the Mac. There are a few others, but I do not remember one that matches your description.
I'm bored and just making something for the heck of it in Python. I saw someone typing with spaces between all their letters and decided to make a python script that does this. It was pretty easy, but then I wanted to take it a step further, because copy/pasting from console takes time, so I want to have this script put spaces after every keyboard press but only when I have Discord as the active window. The only things I could find that could give you the active window are from 5-15 years ago, and are all outdated. They say use win32gui, and I pipinstalled it, but it doesn't seem to work.
EDIT: For clarification, I ran "pip install win32gui" and it installed, I opened a python shell and typed "import win32gui" and it said no such module
I looked through the modules and found win32 and according to the help command win32gui is part of its package, so I tried win32.win32gui and it says there's no such attribute
I'm new to coding, I'm not entirely sure what I'm doing.
It seems win32gui isn't recognized in shell which I was using to test if it worked or not, however after just adding it to an actual python script it works just fine.
This question already has answers here:
Pygame and cx_freeze: segmentation fault
(5 answers)
Closed last month.
I made a game in python, and then exported it with cx-freeze. For some reason, when I try to double-click on the application it opens a command line for about a second and then closes. However, when I run it myself with just the python IDLE it works fine. What am I missing?
If it helps: I have graphic files in a separate folder called data and I'm using the normal python modules + pygame.
If you application is a GUI, you should freeze it with the "Win32GUI" base, so it doesn't open a command line. Have a look at an example in the docs.
I don't know why it's closing again - maybe it's failed to include something it needs. When you freeze it with the GUI base, any error messages should appear in a message box, which might help you work out what the problem is.
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.