How can I open pygame windows outside of PyCharm? - python

I made a game in pygame. It works perfectly fine when run from pycharm. However, when I want to run it from another location, say command prompt or just windows explorer, all that I get is a black screen that briefly pops up before closing.
I have had the same problems when writing code that uses selenium or other imports. I'm quite sure that the imports are the problem. Code without imports works just fine, regardless from where it's run.
I'm sorry if this is a stupid question with an obvious answer, I'm still a beginner.
Thank you in advance, noble people of StackOverflow.

Try to run this command in cmd (outside the environment):
pip install pygame
Mine works fine and, yes, it is a problem related to the imports.

Related

Unable to use turtle in Git Bash

I have only just begun to learn to code in Python. I have a bit of experience in HTML, but that's about it.
I am current taking the Intro to Programming nanodegree from Udacity.
The lessons I am working on is introducing students to using interactive mode via command line to test bits of code. The problem is that I have to use the python -i command to get into interactive mode, and I am unable to scroll through the history. The bigger problem, however, is that running things like the turtle module are spotty.
Following the instructions in the lesson, I am trying to run the following code:
import turtle
amy = turtle.Turtle()
amy.forward(100)
amy.left(90)
amy.forward(100)
etc...
What ends up happening is I am able to import the turtle, assign it the name "amy", but then when I try to give it movement commands, nothing happens. the >>> disappears and Git Bash stops responding. I have to close the terminal and start a new terminal everything.
Also, being unable to use the arrow keys to cycle through command history is frustrating and retyping the code over and over again any time a mistake is time consuming.
Are there any better ways to go about using the CLI to fulfill the requirements of the course? (I didn't say which requirements, because I'm not entirely sure to what extent the course will require me to utilize the CLI on upcoming projects.)
This problem has frustrated me so much and I am not able to get any useful information from the "mentors" on the Udacity forums, so I have basically stopped progressing through the course.
Any help is much appreciated.
One possible alternative would be to use, instead of a git bash shell, a true Linux session through WSL2 if you are using a recent enough Windows version.
That way, you would benefit from a regular shell, in which history would be available through arrow keys to cycle through.
I'm doing the same course and had the same problem. Found a solution at https://granatguitar.com/why-can't-i-run-python-in-git-bash-on-windows/
I tested it first from the $ prompt and it seemed to work OK, so then I set it up in .bash_profile.
I didn't have a .bash_profile file so I created one in ~ and edited it as granat suggested.
I added the line alias pythoni="winpty python" and saved the file. (I used pythoni rather than python because, well, it's python interactive.)
Now, when I enter pythoni at the $ prompt it starts python in interactive mode....and it works! All the problems with hanging and not moving the turtles have gone.

PyGame snake game not running in PyCharm

I am trying to run a python file for a snake game in PyCharm (Community Edition 2020.2). I am using Python 3.8. When I try to run the file, the Python application tries to open, but is never able to to start the game. I feel like there is something wrong with my interpreter. I used the "which python3" command to figure out where my Python3 was installed and am using that location for my interpreter, but again, the application doesn't open upon running. I have attached a screenshot of my interpreter. Any thoughts on what might be wrong would be great
PyCharm automatically creates a virtual env for your work. That might be the root of your problem. You could look up about that to resolve your problem. I am a bit less familar with virtual-envs. Someone else could give you detailed info but it might be the gist.

No Windows popping up while using pygame

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.

Are there any other ways to share / run code?

So I just created a simple script with selenium that automates the login for my University's portal. The first reaction I got from a friend was: ah nice, you can put that on my pc as well. That would be rather hard as he'd have to install python and run it through an IDE or through his terminal or something like that and the user friendliness wouldn't be optimal.
Is there a way that I could like wrap it in a nicer user interface, maybe create an app or something so that I could just share that program? All they'd have to do is then fill in their login details once and the program then logs them in every time they want. I have no clue what the possibilities for that are, therefore I'm asking this question.
And more in general, how do I get to use my python code outside of my IDE? Thusfar, I've created some small projects and ran them in PyCharm and that's it. Once again, I have no clue what the possibilities are so I also don't really know what I'm asking. If anyone gets what I mean by using my code further than only in my IDE, I'd love to hear your suggestions!
The IDE running you program is the same as you running your program in the console. But if you dont want them to have python installed (and they have windows) you can maybe convert them to exe with py2exe. But if they have linux, they probably have python installed and can run you program with "python script.py". But tell your friends to install python, if they program or not, it will always come in handy

How to create desktop python game application in Ubuntu 16.04?

I have written a python game using pygame module. It runs fine from terminal.
I have a game directory (let's call it myGame) which contain all the resources(images and sounds) and all the python scripts which use those.
When I run the game through terminal (let's say python3 mainPythonModule.py), the game runs fine.
I tried to create a game.desktop file. But when I click it, a black window appears and crashes almost instantly.
I am using Ubuntu 16.04 LTS. And my game is written in python3.5 and uses pygame module.
My game.desktop file looks like this
I don't want the solution answered for this question because I still have to type in terminal.
I would like to create a desktop applcation, such that by clicking on the icon, the game would start.
Just like when we download any game, after installation, we just click on the game icon and it runs, I want something like that. How can I do that?
Edit :
I don't think this question is a possible duplicate of this question.
I want to know how to develop a desktop application in Ubuntu 16.04, such that by clicking on some icon, the game would start.
Final Edit :
First of all, I would like to thank everyone who responded. I really am sorry for wasting your precious time.
The issue is resolved. The problem was all the resource (images and sounds) were loaded via relative path and not through absolute path. Now the game.desktop file runs fine.
I think what are you trying to do is some kind of launcher.
Here you have my repo, it contains a Tkinter GUI with a PyGame call on a button.
Feel free to study/use it as you want, look at the file desktop_application.py and if you don`t care about the coin part you can just skip that and take what you need.
https://github.com/FilippoLeone/PyGameLauncher
And you can compile everything as an executable with PyInstaller.
Install PyInstaller from PyPI:
pip install pyinstaller
Go to your program’s directory and run:
pyinstaller yourprogram.py

Categories

Resources