im very new to code in general so this could be a stupid beginner problem ive searched for things but i couldnt find something useful for me
under Problems is the message: Import "pygame" could not be resolved
im very new to code in general so this could be a stupid beginner problem ive searched for things but i couldnt find something useful for me
under Problems is the message: Import "pygame" could not be resolved
You can use pip show pygame
to view the package installed location.
And check whether the installation location is consistent with the version corresponding to the selected Python interpreter.
There are two ways to solve this problem:
pip -t flodername pygame #flodername is your used python package location
. Install the pygame package to the specified directoryFirst, try restarting your computer or vs code
Use this command in your vs code terminal if the above doesn't work:
pip uninstall pygame
Then reinstall pygame using:
pip install pygame
If this also does not work then follow these steps:
Go to the scripts folder of python.
Open command prompt
or Powershell
in the script folder.
Use this:
C:\python34\scripts> python -m pip install pygame
Done
As an Anaconda user, I found my packages were being installed to C:\Users\YOUR_USERNAME\anaconda3\Lib\site-packages
, which Visual Studio Code was not picking up on.
With the Pylance extension installed, open Settings (File > Preferences > Settings
, or Ctrl+,
)
At the top, beside Workspace
, choose User
Under Extensions > Pylance
, scroll until you find Python › Analysis: Extra Paths
and select Add item
.
Type in the path to which packages are being stored (in this case, C:\Users\YOUR_USERNAME\anaconda3\Lib\site-packages
)
Click OK
and after a couple moments, you should see something like the below image (i.e, the path is included in the list of paths).
Finally, your Python file should have picked up on the changes, but if not, reload it or VS Code. If nothing else, add another path that packages are being saved to or change your Python Interpreter. Using another virtual environment's interpreter wouldn't be very helpful, after all.
I may be late, but I hope this helped.