Reputation: 35
import pygame
#initialise
pygame.init()
screen = pygame.display.set_mode((800, 600))
running = True
while running == True:
for event in pygame.event.get():
if event.type == pygame.quit:
running = False
This code actually runs, but the error does not go away. I am following a pygame tutorial that uses pycharm. Is the issue the program I am using?
I'm a beginner and can't figure this out at all.
Upvotes: 3
Views: 16875
Reputation: 1
We need to check if the editor's current Python version matches the correct directory path of the Python imported version. In order to do so,
First, we need to check the Python version shown on the bottom panel of the editor and click on it.
After clicking, we will get the above popup showing all the Python versions currently installed in the local system. Step 1 (Matching Version)
Click the correct directory path (matching the one in which Pygame is currently installed)
You may also edit the default import path from the Python settings.json file (search "Python" inside VS Code "Settings") and add the correct directory path in the "python.defaultInterpreterPath" field.
Step 3 (Adding Correct Directory Path to settings.json)
This solution worked for me!
Upvotes: 0
Reputation: 121
Ensure the python interpreter you are using contains the pygame libraries
Upvotes: 0
Reputation: 41
I have experienced the same problem on VSCode even though the package was already there using pip install pygame and I had to add the library folder in Pylance manually, I copied the library path and pasted it to Pylance extra path setting. It solved my problem. Pylance extra path setting
Upvotes: 2
Reputation: 31
After a long time trying to solve the problem, I had to manually add the library folder in Pylance.enter image description here
It may be that the location of your libraries is in a different place, but after the Python folder the location doesn't change (unless you changed it yourself), in my case it still didn't work, if yours doesn't work either, put: C:\python\python310\lib\site-packages\pygame If you installed without making any changes your python folder is in c:\Users\Your user\AppData\Roaming\Python...
Upvotes: 3
Reputation: 490
@eklavyaisabird - I have faced same issue on VSCode but I had added ./sources
on Pylance extra path setting, it fixed the error
Upvotes: 1
Reputation: 8431
If you are using the global environment, you need to reopen the VSCode after you install the package you want to import.
If you are using the virtual environment, Plycance Language Server
can detect the packages automatically after you installed them.
Upvotes: 3
Reputation: 35
After adding it to the environment using pycharm, it somehow fixed the issue in VSCode as well. Weird. I wonder how I would do the same thing with only vscode.
Upvotes: 0