7

I just installed the beta version of Python 3.10, opened VS Code, changed the Python Interpreter to Python 3.10 64 bit (my PC works with 64 bit) and managed to continue working on my Pygame Project.

Yet, as I runned the code, I faced the ModuleNotFoundError that said : no module named Pygame. (though the pygame module is perfectly installed)

So was that because of the beta version of Python? if yes, aren't there some ways to work with pygame and python3.10 at the same time ?

Developeeer
  • 110
  • 1
  • 1
  • 10
  • 2
    The current release is [Python 3.9.5](https://www.python.org/downloads/release/python-395/). The most recent Pygame version (2.0.1) works well with Python 3.9.5. – Rabbid76 Jun 13 '21 at 09:50
  • 1
    @Rabbdi76, It's still a beta version of Python and you can download it from Python.org – Developeeer Jun 13 '21 at 09:54
  • 1
    @Rabbid76, here is the link : https://www.python.org/downloads/release/python-3100a6/ – Developeeer Jun 13 '21 at 09:55
  • 1
    It's is still a beta version. So you have to wait for a new Pygame release. – Rabbid76 Jun 13 '21 at 09:57
  • 2
    Have you installed pygame in your Python 3.10, or are you assuming it is installed because you installed it before? Each Python interpreter normally has its own, separate set of packages. – Amadan Jun 13 '21 at 09:58
  • 3
    Python doesn't support Pygame. Pygame needs to support the Python version. – Rabbid76 Jun 13 '21 at 09:58
  • @Amadan, I've installed it before , maybe with python 3.9 or less – Developeeer Jun 13 '21 at 09:59
  • 1
    It is almost certainly the case then that this is why your Python 3.10 can't find it. Install it with Python 3.10's pip. (Incompatibility would not result in `ModuleNotFound` for Pygame - the only way Python can figure out there is a compatibility problem with a module is if it executes it, and it can't execute something that it said it can't find.) – Amadan Jun 13 '21 at 10:02
  • 1
    To use pygame on python 3.10, you have to build pygame from source using the latest code on github.com/pygame/pygame – Starbuck5 Jun 13 '21 at 20:43
  • 1
    https://github.com/pygame/pygame/issues/2599 – Dima Tisnek Oct 06 '21 at 05:54

4 Answers4

4

I thin it may be a compatibility issue.

pip3.9 install pygame

works just fine.

pip3.10 install pygame

returns a slew of errors. Some of them were pip/pygame bugs having to do with wheels and dependencies. So I cloned the pygame source repository locally and tried to build it from source.

python3.9 setup.py build;
python3.9 setup.py install

works as expected.

python3.10 setup.py build;
python3.10 setup.py install

reaches the critical limit of 20 errors and decides it's done. I've tried a variety of workarounds and solutions that worked for older versions of both pygame and python but unfortunately nothing has worked, so I think it really is just a compatibility issue and we'll have to wait for pygame to update to work with python 3.10.

Ethan Ray
  • 66
  • 5
3

For MAC users

The Python 3.10 installer is universal, meaning it runs the ARM64 version of Python 3.10 by default. As Pygame is not yet updated to run on ARM64 you need to run Python 3.10 in Rosetta, to do this from the Shell use command: python3-intel64

import pygame will then work just fine with Python 3.10

To use this in VS Code you will need to alter the settings.json file to:

"python.defaultInterpreterPath" : "/usr/local/bin/python3-intel64"

Then select interpreter from the editor.

Edster
  • 143
  • 2
  • 8
1

If pip install pygame with python 3.10 produces errors, you could always try again by installing with a .whl file from this website: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame

Installing would probably look like this:

pip install {path-to-whl-file}/pygame-2.0.1-cp310-cp310-win_amd64.whl

trobblob
  • 34
  • 3
1

I've faced the same issue and VSCode actually explains what is going on, and thanks to @Edster I could solve it.

TL:DR: Set defaultInterpreterPath to a different value and reset it to python

The description for the option Edster mentioned is:

Path to default Python to use when extension loads up for the first time, no longer used once an interpreter is selected for the workspace. See https://aka.ms/AAfekmf to understand when this is used

And when you go to the link the important information is:

Changes to the python.defaultInterpreterPath will not be picked up by the Python extension once user explicitly chooses a different interpreter for the workspace. The extension will also not set nor change the value of this setting, it will only read from it.

In my case the project was loaded using the unversioned python symlink pointing to 3.9 and then I've downloaded 3.10 and updated my PATH to have python pointing to 3.10, but when I did that since the value of defaultInterpreterPath didn't change on VS code it didn't try to pick it up again.

My assumptions are that defaultInterpreterPath doesn't store the symlink itself but where it points.

  • Changing it to a different value and resetting the value to python fixed the issue for me, but I assume if you just disable/enable the Python extension on VSCode it should work.

Disclaimer: These are just assumptions and I haven't tried them on my end, feel free to comment here the outcome if you try it or if you have anything to add.