Can't install library in the macOS terminal

I tried to install the library from python but the terminal error message is:
Defaulting to user installation because normal site-packages is not writeable

Requirement already satisfied: pygame in ./Library/Python/3.9/lib/python/site-packages (2.5.2)

WARNING: You are using pip version 21.2.4; however, version 23.3.1 is available.

You should consider upgrading via the ‘/Library/Developer/CommandLineTools/usr/bin/python3 -m pip install --upgrade pip’ command.

But when I come back to python, sublime text, it says this: ModuleNotFoundError: No module named ‘pygame’

Thanks for reading this.

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:

import sys

From the paths I assume use are a macOS user.

The version of python that ships with macOS is old.

I suggest that you first install a newer version of python from
I tested that pygame installs with python 3.12 (the latest version).

When you install python it will edit your zsh profile so that python3.12 is on the PATH.
After installing python 3.12 start a new terminal and type:


You should see that you have python3.12
To use pip with python3.12 type

python3.12 -m pip install pygame

That way you will use the right version of pip for python3.12.

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.

This line appeared which I think is good?

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

% 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.
>>> ^D

% python3.12 -m pip

  /usr/local/bin/python3.12 -m pip <command> [options]

  install                     Install packages.
  download                    Download packages.

it says that not modoled named piip in the terminal

that was a typo, it should be pip

Opss… I fixed the typo in my post. I got it right in the example output.

still do not work

Can you copy and paste the exact terminal output so we can see what the error is? Simply telling us it didn’t work is not very useful.

1 Like

Tell the output of these commands

echo $PATH
which python3.12



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.

1 Like

my python version is: Python 3.13.0a1

Unless you are a python expert planning your support for end of 2024 do not use python 3.13. Best released version is 3.12.

there is still a version for macos python 3.13:

The 2nd column

Yes it says “pre release” and most packages will not be supported yet. Just use 3.12.

I still have the same error