I tried to install pygame with Python 3.12 and using Poetry to manage dependencies:
The dependencies list in the pyproject.toml
file:
[tool.poetry.dependencies]
python = "^3.12"
pygame = "^2.5.2"
I ran poetry install
and received the following error:
...
File "/Users/r_2009/Library/Caches/pypoetry/virtualenvs/coffeeshop-It7qMoV3-py3.12/lib/python3.12/site-packages/pip/_internal/metadata/importlib/_envs.py", line 111, in _find_eggs_in_dir
from pip._vendor.pkg_resources import find_distributions
File "/Users/r_2009/Library/Caches/pypoetry/virtualenvs/coffeeshop-It7qMoV3-py3.12/lib/python3.12/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2164, in <module>
register_finder(pkgutil.ImpImporter, find_on_path)
^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
I was able to fix this by upgrading pip
to the latest version in the virtual env.
The virtual env was created by Poetry so I entered the shell:
poetry shell
and then ran the following commands:
python -m ensurepip --upgrade
pip3 install --upgrade pip
pip3 install --upgrade setuptools
This runs the ensurepip module's function to upgrade the installed version of pip and that the latest version of pip is installed.
After running that I was able to run poetry install
with no errors and able to run Python scripts.