pygame / pygame

🐍🎮 pygame (the library) is a Free and Open Source python programming language library for making multimedia applications like games built on top of the excellent SDL library. C, Python, Native, OpenGL.
https://www.pygame.org
7.5k stars 3.34k forks source link

PyGame not working in vs studio #4360

Open Rednaskela500 opened 1 month ago

Rednaskela500 commented 1 month ago

After the update of vs studio i tried to run my pygame file. But there was an error ModuleNotFoundError. I tried redownloading pygame. Could someone help me please?

DarthKitten2130 commented 1 month ago

if you're using a virtual environment (if you're not you should be), perhaps your visual studio is no longer running the program in your virtual environment, and it's trying to run your program on the global interpreter, which doesn't have pygame installed I'm assuming. can i have more info, like a screenshot of the command line perhaps?

Also is it Visual Studio or Visual Studio Code? Those are two very different pieces of software.

Also this is probably 95% not a PyGame issue, and i wouldn't encourage you to go to the GitHub issues page for something like this. Try reddit or ChatGPT first. Good luck!

Rednaskela500 commented 1 month ago

I use vs code, sorry for that. I tried chat gpt it said that it is an update problem because 'import keyboard' also doesn't work. And I don't know what a virtual environment is. I saw that some people used it but I really didn't want to use it because it really seems complicated.

When I runned my code with pygame it said ModuleNotFoundError. I reinstalled it but it also didn't work.

And if I spelled something wrong. Sorry English is my fourth language. Thanks

DarthKitten2130 commented 1 month ago

i still think it is an environment problem. Let's use a virtual environment to fix it. A virtual environement lets you use an isolated python interpreter because installing libraries on the global interpreter causes errors like this.

First, delete all the packages you installed on the global python, including pygame, keyboard, etc

Next, download virtualenv with this command - pip install virtualenv

after you install virtualenv, run this command - virtualenv venv This creates an environment called venv, which you can use to run pygame.

Assuming you use Windows, go to the command line and type .\venv\Scripts\activate to activate your venv.

Now, use pip to download pygame, keyboard, and whatever other packages you're using, in the venv.

VS Code auto-detects venvs, so in the bottom right corner where it asks for the python interpreter you want to use, click on your venv instead of the normal python interpreter. Now run the program and see if the problem goes away.