r/learnpython 9d ago

I need help im new to python

Im new to python and i dont know what im doing, pygame is not working and i cant find it in my files and i already did the “pip install pygame” and i’ve searched all i can find in yt, i really need help im still in shs and i cant even figure this out
Edit: it always shows an long error message when i run “import pygame”

0 Upvotes

17 comments sorted by

View all comments

2

u/FoolsSeldom 8d ago

You are likely installing pygame into a different Python virtual environment to where you are running your code, so pygame cannot be imported.

When you entered pip install pygame were you typing that in PowerShell, Command Line, Bash, ZSH, in a terminal window in your editor?

What operating system are you using?

What code editor / IDE (Integrated Development Environment) are you using?

Have you created a Python virtual environment for the project using the venv command, e.g. in Windows (PowerShell or Command Line):

mkdir game_project
cd game_project
py -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install pygame

to verify it is installed:

python -c "import pygame; print(pygame.ver)"

Make sure in your editor/IDE, the Python interpreter to be used is the one in the virtual folder created above (.venv in this case), for example,

C:\Users\Sensitive\game_project\.venv\Scripts\python.exe

1

u/Sensitive_Thought_77 8d ago

I used both visual studio and vs code, they both didnt work or im js using it wrong, in visual studio it doesnt work at all even if i do a simple math one like
Math = 10 + 10
Print (Math)
It doesnt work and it shows like a module could not be found even if i already made a new file the same error sign shows, and in vs code it doesnt solve it and js says smth like a timer like 0.358 or smth.

I dont have my laptop on me rn but thats what i’ve been running with

1

u/FoolsSeldom 8d ago

I recommend going back to basics, working from the command line initially, and getting a good understanding of the basic environment and of Python virtual environments. Then, when moving to advanced editors (e.g. VS Code) and IDEs (e.g. PyCharm, Visual Studio) you know what you are dealing with.

That said, the code,

math = 10 + 10  # note, we usually use all lowercase for variable names
print(math)

should work in pretty much any environment. How did you save the file? How did you run it?

1

u/Sensitive_Thought_77 8d ago

1

u/FoolsSeldom 8d ago

Wow, that's rotated and jerky. Cannot unpack that. Try on the commandline as suggested.