Tip: it’s easier for us to read output from the terminal if you format with as code, with ``` (or select the text and hit the </> button)
Regarding your issue: you might have multiple versions of Python installed, and the version your script is using is different from the one where you installed pygame. In your code, try importing the sys module and printing out the path to your executable:
I think I install the 3.12 version with mac os sonoma (latest) and I don’t know what happend
But the the terminal still print this:
/Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12: No module named pip.main; ‘pip’ is a package and cannot be directly executed
When I type pip3, it still print out the original line but I don’t know what happend.
3.13? 3.13 hasn’t been released, I’m guessing you meant 3.12 like you wrote above?
In your original post, the text reads Requirement already satisfied: pygame in ./Library/Python/3.9/lib/python/site-packages (2.5.2). Note the 3.9 in there–that’s the version of pip you ran, and the version of python that had the package installed. If the version of python you’re running in another context is 3.12, that explains why it isn’t finding the package (because it was installed somewhere else).
The python3.12 -m pip install pygame command should work to install it in that environment, you should double-check that you entered the command correctly (the -m is important). If it doesn’t work, copy the input and output exactly and post it with code formatting (the </> button at the top of the post editor).
This is what I see on my mac. Notice that I do not use the pip3 command becuase its hard to be sure what python it will use. Using python3.12 -m pip means it is always the pip that matches the python. /usr/local/bin should be on your PATH as it added by the python installation process.
% which python3.12
Python 3.12.0 (v3.12.0:0fb18b02c8, Oct 2 2023, 09:45:56) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
% python3.12 -m pip
/usr/local/bin/python3.12 -m pip <command> [options]
install Install packages.
download Download packages.
I’m confused how you got /Library/Frameworks/Python.framework/Versions/3.13/bin on your path–did you install from source or something? 3.13 won’t be released for a year.
From googling this error, it seems likely that there is some combination of bad Python installs that causes python3.12 to not find the pip module. I’m not sure how to repair it because I don’t know what’s been messed up, but my first suspect is that supposed 3.13 installation.