-2

I have been trying to install pygame on Spyder for hours. I remember doing it on another computer, and it worked just fine, but this time nothing fixes the issue I have. Whenever I try to run a 500-line code I did back in the day, an error message appears on the first line of code (import pygame) saying

No module named 'pygame'".

I installed Anaconda3, and typed "pip install pygame". Successful download. Pygame even appears even when I type "pip list". But the program cannot be run. I don't know which prompt I am supposed to use, the default command prompt, the Anaconda prompt, or the Python prompt to type commands. Spyder version is 5.4.5, Python version is 3.8.10, Pygame version is 2.5.1. I also tried to manually copy-paste pygame into Spyder's and Python's "lib" folders. I searched for alternate commands, but none of them worked (--user, pip3).

pppery
  • 3,731
  • 22
  • 33
  • 46
Tagad
  • 1
  • 1
  • How exactly do you run code? From the command line, or an IDE, or some other way? What is the exact command? – John Gordon Sep 02 '23 at 23:52
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 03 '23 at 04:08

1 Answers1

-1

It seems like the issue is that Pygame is installed but not available to import in your Python environment in Spyder. Here are a few things you can try:

# In Anaconda Prompt
python -m pip install pygame

# In Spyder console 
import sys
sys.path.append('C:\\Path\\To\\Pygame\\Install') 

import pygame

The first option reinstalls Pygame specifically for your Python installation that Spyder is using.

The second option manually adds the Pygame install directory to the module search path so it can be imported.

You may also need to restart the Kernel in Spyder after installing to pick up changes.

Make sure you are installing Pygame for the same Python version that Spyder/Anaconda is using to avoid version conflicts.

pwoltschk
  • 550
  • 1
  • 3
  • 22