#๐Ÿ”’ I am trying to learn how to activate pygame

254 messages ยท Page 1 of 1 (latest)

sullen igloo
high lichenBOT
#

@sullen igloo

Python help channel opened

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.

sullen igloo
frank marlin
#

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)

final jewel
#

(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?

sullen igloo
#

Yes

#

Python -v does not produce any output

#

I think the tutorials would be a great place to start. I agree

final jewel
#

howbout: python (no args)? (to get out, ctrl-D)

#

let's see if you can import pygame...

sullen igloo
#

Apparently putting Pygame in the name of the program is a big no no

frank marlin
#

pip -V ? it should show the path to pip... which should match the path to your python installation (to some degree)

final jewel
#

you can also say: which pip (especially if you're running linux)

sullen igloo
#

$ 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)

final jewel
#

oh, windows?

sullen igloo
#

my bad I typed version

frank marlin
#

that looks like a microsoft store version.

sullen igloo
#

yes

#

this is running on visual studio code

final jewel
#

yeah, and backslashes for dir separrrrrrators

frank marlin
#

then those two versions are probably conflicting

sullen igloo
#

how do i remove versions?

frank marlin
#

go to your windows settings -> apps -> search for python, and try to uninstall the microsoft store version (3.10 it seems)

final jewel
#

hmm. keyboard acting up

sullen igloo
#

found it... uninstalling

frank marlin
#

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)

final jewel
#

python is pretty completely object oriented... meaning all values, even integers, and bools (like True and False) are ob jects

frank marlin
final jewel
#

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

sullen igloo
#

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.
final jewel
#

which is he gonna install? or did he already?

frank marlin
#

yea, it's possible you didn't install python into PATH on installation

#

try to use py instead

#

(and py -m pip install pygame )

sullen igloo
#

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

final jewel
#

(later, someone will tell you about these container things for modules that you can make, called "virtual ennnvironments"

sullen igloo
#

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

frank marlin
#

in vscode? you probably need to switch to the correct python version yes.

#
py -c 'import sys; print(sys.executable)'
final jewel
#

see if "which python" says aomething (leave the quotes out though)

frank marlin
#

^ (only works if python is on PATH, which doesn't seem the case)

sullen igloo
#

@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
frank marlin
sullen igloo
#

@final jewel

which python output

Andrew@DESKTOP-CGDG53G MINGW64 ~/Desktop/pygame_projects
$ which python
/c/Users/Andrew/AppData/Local/Microsoft/WindowsApps/python
frank marlin
#

that python is something else I believe.

#

it's a "placeholder" app, that's not actually python

final jewel
#

heyy it works ๐Ÿ™‚ so: which someexe tells you where on the disk someexe is

#

you can also try: which py

sullen igloo
#

mission success

frank marlin
final jewel
#

yep, that's hello world on a pygame window?

sullen igloo
#

@frank marlin @final jewel

Thank you! both of you! how can I get better at troubleshooting

frank marlin
#

which is why I showed how to print the actual python.exe with py, using sys.executable.

sullen igloo
#

@final jewel

correct sir

final jewel
#

so you used pygame (so you would have had to "activate" it by making the name "pygame" visible to your code, by importing it

frank marlin
sullen igloo
#

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.

final jewel
#

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"

frank marlin
final jewel
#

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)

sullen igloo
#

i will try to build more python projects and develop my trouble shooting skills further. but I need to define the problem further

final jewel
#

wanna try a few things?

#

I'll show you a little bit

sullen igloo
#

yeah

final jewel
#

ok, start a python... let me know when it prints its >>> prompt

#

then we can get started

sullen igloo
#

start python in visual studio code or in the python shell?

#

shell, gotcha

final jewel
#

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

sullen igloo
#

I am ready

final jewel
#

ok, first: variaables... remember I said all values in python are objects?

sullen igloo
#

yes

#

I have taken codecademys courses on object oriented programming, functions, and variables.

final jewel
#

objects can have all kinds of different types... two basic types are: integers and strings

sullen igloo
#

I have a basic understanding of data types as well, lists, strings, dictionaries, and tuples

#

but I am

#

struggling in troubleshooting

final jewel
#

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"

sullen igloo
#

on it

#
a = "hello"

> >>>
final jewel
#

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:

sullen igloo
#

ok

final jewel
#

print("hi there")

#

(that would run too, you can try it if you want)

sullen igloo
#
a = "hello"
>>> print("hi there")
hi there
>>>
high lichenBOT
#

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.
final jewel
#

yes, 'hello world' is also a "literal value" (which, like all other data in python, an object)

sullen igloo
#
print("hi there")
final jewel
#

oh, the bot is squaking ๐Ÿ˜›

#

we also have that variable too

sullen igloo
#

technology hates me

final jewel
#

try shis: print(a)

sullen igloo
#

print(a)
hello

final jewel
#

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)

sullen igloo
#

type(a)
<class 'str'>

final jewel
#

that's fancy tech stuff for "it's a string"

#

have you dealt with if or else or def?

sullen igloo
#

yes

#

control flow

final jewel
#

so you know about indents

sullen igloo
#

i do

#

however i still make indentation errors from time to time

final jewel
#

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"

sullen igloo
#

ok

final jewel
#

then try: a + 5

sullen igloo
#

b = "world"

final jewel
#

see what THAT gets ya

sullen igloo
#

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate str (not "int") to str

final jewel
#

can't add string and int

#

try: a + str(54)

#

that str() converts whatever it gets to a string

sullen igloo
#

a + str(54)
'hello54'

final jewel
#

now try: a + b

sullen igloo
#

a + b
'helloworld'

final jewel
#

hmm. small problem...

#

try this: a + " " + b

sullen igloo
#

a + " " + b
'hello world'

#

a space

final jewel
#

yep, when there was NOT a space before

#

and finally, you can try these:

#

a = 5

#

b = 4

#

and then,

#

a + b

sullen igloo
#

a + b
9

final jewel
#

and then,

#

a + str(b)

sullen igloo
#

a + str(b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'

final jewel
#

can't add an int and a string

#

notice you're getting a "TypeError"

#

that will be important later

sullen igloo
#

so that means I cannot add str to integer

final jewel
#

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

sullen igloo
#

oh! so if it shows type(int) type(str) is unacceptable

final jewel
#

yes, and it depends on what you're doing

#

try: "hello" * 5

sullen igloo
#

I did not know that

final jewel
#

maybe you expect it can't do that

#

but maybe it can

sullen igloo
#

attempting

#

"hello" * 5
'hellohellohellohellohello'

#

lol

#

thats interesting! it multiplied the string values by 5

final jewel
#

yeah, that can be handy sometimes

sullen igloo
#

๐Ÿ™‚ I need to write that down

final jewel
#

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
sullen igloo
#

return allows values to escape the function call. they don't hold data but they are the calculated outcome

final jewel
#

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

sullen igloo
#

I really appreciate it jimm

final jewel
#

welcome ๐Ÿ™‚

sullen igloo
#

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

final jewel
#

yeah, and/or do more tutorials (which are usually projects that it gives you a piece at a time, and explains the piece)

sullen igloo
#

Any resources you reccomend in particular?

final jewel
#

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

sullen igloo
#

I will have this bookmarked. ๐Ÿ™‚

final jewel
#

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

sullen igloo
#

could you send me the link?

final jewel
sullen igloo
#

sees practice python.org
reviews material
I can finally work to do list comprehensions which are annoying to me, but necessary.

sullen igloo
#

subscribed!

final jewel
#

I don't understand the question

#

oh I see

sullen igloo
#

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?

final jewel
#

sure... and, you can also ask the people on the discord, some of whom are python devs

sullen igloo
#

๐Ÿ™‚ thank you for your help!

final jewel
#

welcome ๐Ÿ™‚ good luck... oh by the way, are you using git?

sullen igloo
#

yes

#

๐Ÿ™‚

final jewel
#

good

sullen igloo
#

๐Ÿ™‚

final jewel
#

very good... looks like you have pretty much everything you need

sullen igloo
#

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?

final jewel
#

well you can go for anything you can find...

#

oh I got something you might like

sullen igloo
#

I want to use these resources when I troubleshoot next.

final jewel
#

iteration is one of python's major strengths

#

and some guy did a talk on it

sullen igloo
#

he seems to be a fast talker and very blunt ๐Ÿ™‚

final jewel
#

yep

#

maybe you've spoken to him before

sullen igloo
#

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.

final jewel
#

well, I offered them in the hope they'd be useful

#

ok, cool

sullen igloo
#

๐Ÿ™‚ i have to go to bed ๐Ÿ™‚

#

talk to you later ๐Ÿ™‚

final jewel
#

some of us do

#

ok, see you another time

sullen igloo
#

!solved

high lichenBOT
#
Python help channel closed

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.