0

I can't use pygame package in Pycharm. I have installed it with pip but I can not use it. When I tried to install it from the error that appeared in the IDE or from 'Python Packages', it gave me an error. I also tried pip install pygame --pre and it's not working. It says that 'Requirement already satisfied:' but I still can not use it. What should I do?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Albert
  • 9
  • Pygame doesn't currently install easily with Python 3.11, especially on Windows. Try using Python 3.10 instead. – MattDMo Jan 29 '23 at 02:08

3 Answers3

0

You should be able to left click on the module. It will display a download packages button. You need internet but should be able to download it. You don't to use the command prompt to install packages. That is only for the python IDLE.

0

Go here and click install. Pycharm using his own registry of packages. https://i.stack.imgur.com/Yox6D.jpg

thief01
  • 1
  • 2
0

So, you're using PyCharm, it likely means it has created a new virtual environment when you created your project, to install packages in that environment it's easiest to either use PyCharm's Package Manager or Terminal. In the case of using Python 3.11 you'd need to supply the --pre flag when installing pygame because the full release of 2.1.3 has not yet been released and 2.1.3.dev8 which is a pre release is the latest one that has 3.11 wheels for installation. More information about that particular thing can be found here: https://stackoverflow.com/a/74188087/14531062

So, on PyCharm you'd want to use the Terminal: enter image description here When you switch to it, you'll likely find that it basically is PowerShell (unless you have changed it to use CMD which I doubt) (you'll see PS at the start of each line) so the easiest steps to install pygame would be to type in these commands in this order (press the enter key after each line):

cmd
venv\scripts\activate
pip install pygame --pre

After running these commands pygame should be installed in the correct environment and you should be able to import it without any issues.

Screenshot of how it might look when you follow the steps: enter image description here

Matiiss
  • 5,970
  • 2
  • 12
  • 29