#๐ I am trying to learn how to activate pygame
254 messages ยท Page 1 of 1 (latest)
@sullen igloo
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
it's likely that your vscode is configured with a different python than the one in your terminal
pip -V
can't really follow what's going on in your gif ... if you somehow can't select the same python version as your pip uses, I don't really know how to help (don't use vscode myself)
(you may have already learned that...) to activate pygame, you do something that is meant to expose the name pygame to your program
the two things for that:
(1) you need to install pygame
(2) once installed, you would import pygame
once you import it, the name pygame is available to yourr program, and you can use it. sometimes, a name (such as pygame) will have pieces attached, that you can get by their name, for example, if x and y were pieces of pygame, you could access them using pygame.x and pygame.y (so, note the "." operator, for that)
you can start to learn to use pygame, there are lots of tutorials, some videos
pygame itself, is a "python module" that can be installed using pip
@sullen iglooare you here?
Yes
Python -v does not produce any output
I think the tutorials would be a great place to start. I agree
howbout: python (no args)? (to get out, ctrl-D)
let's see if you can import pygame...
Apparently putting Pygame in the name of the program is a big no no
pip -V ? it should show the path to pip... which should match the path to your python installation (to some degree)
you can also say: which pip (especially if you're running linux)
$ pip -V
pip 23.0.1 from C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\site-packages\pip (python 3.10)
oh, windows?
my bad I typed version
that looks like a microsoft store version.
did you also install python from python.org?
yeah, and backslashes for dir separrrrrrators
then those two versions are probably conflicting
how do i remove versions?
go to your windows settings -> apps -> search for python, and try to uninstall the microsoft store version (3.10 it seems)
hmm. keyboard acting up
on it
found it... uninstalling
note: after that "pip" might no longer point to the same python version, so a reinstall of pygame might be needed (and restart of vscode before that to reset your terminals - so they find the new pip location)
python is pretty completely object oriented... meaning all values, even integers, and bools (like True and False) are ob jects
that's kind of unrelated to the topic though
to create your own kinds of objects, you can make your own "class", and then use that class to make objects
buttt more on that later
Andrew@DESKTOP-CGDG53G MINGW64 ~/Desktop/pygame_projects
$ python hello_world_game.py
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
which is he gonna install? or did he already?
yea, it's possible you didn't install python into PATH on installation
try to use py instead
(and py -m pip install pygame )
on it
its downloading pygame!
Andrew@DESKTOP-CGDG53G MINGW64 ~/Desktop/pygame_projects
$ py -m pip install pygame
Collecting pygame
Downloading pygame-2.5.2-cp312-cp312-win_amd64.whl.metadata (13 kB)
Downloading pygame-2.5.2-cp312-cp312-win_amd64.whl (10.8 MB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 10.8/10.8 MB 10.7 MB/s eta 0:00:00
Installing collected packages: pygame
Successfully installed pygame-2.5.2
(later, someone will tell you about these container things for modules that you can make, called "virtual ennnvironments"
attempting to run the program
Andrew@DESKTOP-CGDG53G MINGW64 ~/Desktop/pygame_projects
$ C:/Users/Andrew/AppData/Local/Microsoft/WindowsApps/python3.10.exe c:/Users/Andrew/Desktop/pygame_projects/hello_world_game.py
bash: C:/Users/Andrew/AppData/Local/Microsoft/WindowsApps/python3.10.exe: No such file or directory
output-> I percieve python 3.10 is gone. so I need to switch to the newest version
in vscode? you probably need to switch to the correct python version yes.
py -c 'import sys; print(sys.executable)'
see if "which python" says aomething (leave the quotes out though)
^ (only works if python is on PATH, which doesn't seem the case)
@frank marlin on it
@final jewel that makes sense
Andrew@DESKTOP-CGDG53G MINGW64 ~/Desktop/pygame_projects
$ py -c 'import sys;
> print(sys.executable)'
C:\Python312\python.exe
that should print the path to the python.exe, that py uses by default.
try to find/select it in vscode.. I think in doubt you can even open a file browser and select it directly.
@final jewel
which python output
Andrew@DESKTOP-CGDG53G MINGW64 ~/Desktop/pygame_projects
$ which python
/c/Users/Andrew/AppData/Local/Microsoft/WindowsApps/python
that python is something else I believe.
it's a "placeholder" app, that's not actually python
heyy it works ๐ so: which someexe tells you where on the disk someexe is
you can also try: which py
py is in system32 ... which will not point to the actual python that py uses, as the py command only delegates to the actual python exe ... ๐
yep, that's hello world on a pygame window?
@frank marlin @final jewel
Thank you! both of you! how can I get better at troubleshooting
which is why I showed how to print the actual python.exe with py, using sys.executable.
@final jewel
correct sir
so you used pygame (so you would have had to "activate" it by making the name "pygame" visible to your code, by importing it
really only with experience. I already knew that microsoft store version can cause pip issues (due to people having issues with it here repeatedly), and I know that a lot of people forget to add python to PATH when installing (it's a checkbox on the installer)....
using py is often a fail safe option on windows to some degree.
does this come by working on projects and than getting to a point where you observe open tickets on here and see other troubleshooters work? Maybe making notes about solutions? I am considering that being the path forward.
I'll have to agree: you need to see what python does, and when python does -not- do that, you would try to figure out why
that part of troubleshooting is called "determining the problem"
looking at other peoples issues definitely helps. But the whole python ecosystem is quite complicated - especially if multiple versions are involved ... but I always thought using different python versions on windows was way easier than on linux ๐
certainly, you can learn by observing others, sure; ultimately, you'll be able to learn by obseeerving what python does when it runs -your- code
(sometimes others will be working on things that you're not famiiar with yet)
i will try to build more python projects and develop my trouble shooting skills further. but I need to define the problem further
yeah
ok, start a python... let me know when it prints its >>> prompt
then we can get started
well probably in the windows prompt
you can start it using that bash shell if you want
just let me know when you get the >>> prompt
I am ready
ok, first: variaables... remember I said all values in python are objects?
yes
I have taken codecademys courses on object oriented programming, functions, and variables.
objects can have all kinds of different types... two basic types are: integers and strings
I have a basic understanding of data types as well, lists, strings, dictionaries, and tuples
but I am
struggling in troubleshooting
a variable can hold an object
ok good... I'll hurry up through this part then
run this at the python prompt (the >>>): a = "hello"
good
now you have a name, "a", that is bound to the object, which is a strong
sstring
one thing you can use for trouble shooting, is the print cmd
you can print a literal value:
ok
a = "hello"
>>> print("hi there")
hi there
>>>
Hey @sullen igloo!
It looks like you incorrectly specified a language for your code block.
Make sure you put your code on a new line following py. There must not be any spaces after py.
Here is an example of how it should look:
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
You can **edit your original message** to correct your code block.
yes, 'hello world' is also a "literal value" (which, like all other data in python, an object)
print("hi there")
technology hates me
try shis: print(a)
print(a)
hello
technology is like data, it hhas not ability to feel anything (like hate)
since the thing in the variable a is an OBJECT, it has a type
try this: type(a)
type(a)
<class 'str'>
so you know about indents
C would do something like
if(somecondition)
{
dosomeeething
}
whereas python,
if condition: (note! colon important)
do something
but you know that stuff already... just a reminder
back to variables...
do this: b = "world"
ok
then try: a + 5
b = "world"
see what THAT gets ya
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate str (not "int") to str
can't add string and int
try: a + str(54)
that str() converts whatever it gets to a string
a + str(54)
'hello54'
now try: a + b
a + b
'helloworld'
yep, when there was NOT a space before
and finally, you can try these:
a = 5
b = 4
and then,
a + b
a + b
9
a + str(b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
can't add an int and a string
notice you're getting a "TypeError"
that will be important later
so that means I cannot add str to integer
yes
but you CAN add string to string and int to int
one thing... the + SEES the types on the left and the right of the +
so it's SENSITVE to the type
oh! so if it shows type(int) type(str) is unacceptable
I did not know that
attempting
"hello" * 5
'hellohellohellohellohello'
lol
thats interesting! it multiplied the string values by 5
yeah, that can be handy sometimes
๐ I need to write that down
so... this has been a little thing about how python is object oriiiented
-everything- is an object, all objects have a type
objects are "first-class", which means:
- you can assign any object to a variable
- you can accept an object as a parameter to a function
- you can have a function "return" an object, so it becomes the "value" of the function
return allows values to escape the function call. they don't hold data but they are the calculated outcome
there are a couple more "rights" a first-class object has, I forgot em
yeah, return can throw out any kind of value
so that's it.. those things can help with some kinds of troubleshooting
I really appreciate it jimm
welcome ๐
it sounds to me like the next thing I need to do is build more small projects
and than eventually, a mid project
and maybe, with the help of a team, helpful software
yeah, and/or do more tutorials (which are usually projects that it gives you a piece at a time, and explains the piece)
Any resources you reccomend in particular?
part of troubleshooting is making sure you have the program typed in right
it seems like you have basic python, syntax, conditional structures
there's a book that might be handy
I will have this bookmarked. ๐
I dunno if you want this, but I'll offer: I got an 11-hour video that does a pretty good job of teaching basic python
could you send me the link?
this is something else: https://www.practicepython.org/
sees practice python.org
reviews material
I can finally work to do list comprehensions which are annoying to me, but necessary.
subscribed!
I did not provide the context that was my fault
Thank you for these resources, can I send you questions from time to time?
or just use the python discord?
sure... and, you can also ask the people on the discord, some of whom are python devs
๐ thank you for your help!
welcome ๐ good luck... oh by the way, are you using git?
good
๐
very good... looks like you have pretty much everything you need
Well...
one more thing
so in python apparently you write and or type out things that you than create later.
my second main problem has been trying to figure out what tools to use next
i've done tutorials and they are great but I am seeing a lot of len(range) stuff
python combos
how do I learn those?
I want to use these resources when I troubleshoot next.
he seems to be a fast talker and very blunt ๐
I promise to review these materials ๐
thank you jimm I will be reaching out in a week or so ๐ its cool to meet a new friend.
!solved
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.