Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building error with macOS Big Sur (11.0.1) #2346

Closed
Bodanor opened this issue Nov 19, 2020 · 35 comments
Closed

Building error with macOS Big Sur (11.0.1) #2346

Bodanor opened this issue Nov 19, 2020 · 35 comments

Comments

@Bodanor
Copy link

Bodanor commented Nov 19, 2020

Environment:
OS : macOS Big Sur 11.0.1 Build (20B29)
Pygame : 2.0.0
Python : 3.9, tried also with 3.8

Current behavior:
Build error when installing from pip3

Steps to reproduce:

  1. sudo pip3 install pygame

Stack trace/error output/other error logs

sudo pip3.9 install pygame             
WARNING: The directory '/Users/chris/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pygame
  Downloading pygame-2.0.0.tar.gz (5.5 MB)
     |████████████████████████████████| 5.5 MB 4.0 MB/s 
    ERROR: Command errored out with exit status 1:
     command: /usr/local/opt/python@3.9/bin/python3.9 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-3y9r_p_g/pygame/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-3y9r_p_g/pygame/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/tmp/pip-pip-egg-info-hxgx9bow
         cwd: /private/tmp/pip-install-3y9r_p_g/pygame/
    Complete output (27 lines):
    
    
    WARNING, No "Setup" File Exists, Running "buildconfig/config.py"
    Using Darwin configuration...
    
    /bin/sh: sdl2-config: command not found
    /bin/sh: sdl2-config: command not found
    /bin/sh: sdl2-config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/tmp/pip-install-3y9r_p_g/pygame/setup.py", line 318, in <module>
        buildconfig.config.main(AUTO_CONFIG)
      File "/private/tmp/pip-install-3y9r_p_g/pygame/buildconfig/config.py", line 221, in main
        deps = CFG.main(**kwds)
      File "/private/tmp/pip-install-3y9r_p_g/pygame/buildconfig/config_darwin.py", line 131, in main
        [DependencyProg('SDL', 'SDL_CONFIG', 'sdl2-config', '2.0', ['sdl'])],
      File "/private/tmp/pip-install-3y9r_p_g/pygame/buildconfig/config_unix.py", line 39, in __init__
        self.ver = config[0].strip()
    IndexError: list index out of range
    
    ---
    For help with compilation see:
        https://www.pygame.org/wiki/MacCompile
    To contribute to pygame development see:
        https://www.pygame.org/contribute.html
    ---
    
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Does someone else have this problem ?

I've tried installing SDL2 with homebrew, and I got another error but It still don't want to build it. So yeah there is bug when building it.

@Bodanor Bodanor added the bug label Nov 19, 2020
@MyreMylar
Copy link
Contributor

This looks like it didn't download the wheel for pygame 2.0.0 from pip so it tries to build from source. I assume the source build didn't work because some/all of the dependencies were missing.

I wonder if the command:

sudo pip3.9 install pygame

doesn't work and you actually just need:

sudo pip3 install pygame

?

@Bodanor
Copy link
Author

Bodanor commented Nov 21, 2020

This looks like it didn't download the wheel for pygame 2.0.0 from pip so it tries to build from source. I assume the source build didn't work because some/all of the dependencies were missing.

I wonder if the command:

sudo pip3.9 install pygame

doesn't work and you actually just need:

sudo pip3 install pygame

?

Yeah actually with Big Sur, Apple has moved some dependencies on other locations so yeah building from source doesn't work. I tried both with pip3 and pip3.9

@MyreMylar
Copy link
Contributor

MyreMylar commented Nov 21, 2020

looks like this is a bug with pip and mac wheels, see:

numpy/numpy#17784 and pypa/packaging#319

pip looks for a macosx_11 wheel and doesn't try the macosx_10_9 wheel even though it should. So for now, until the bug in pip is fixed it looks like the easiest solution is to manually download the correct 10_9 wheel for your platform and rename it to 11.

Link:

https://files.pythonhosted.org/packages/94/da/60c4cfa05c51928bbc7954fc33750e0ae16dd3794e9c4b797ff7b051faf8/pygame-2.0.0-cp39-cp39-macosx_10_9_intel.whl

then rename to:

pygame-2.0.0-cp39-cp39-macosx_11_0_intel.whl

and try and manually install the wheel with:

pip install pygame-2.0.0-cp39-cp39-macosx_11_0_intel.whl

from the directory with the wheel file in it. See if that works.

@Bodanor
Copy link
Author

Bodanor commented Nov 21, 2020

Thank you it worked as expected !

@BlueSage96
Copy link

This workaround doesn't work for M1 macs.

@MyreMylar
Copy link
Contributor

It sounds like this bug was fixed in the latest version of pip so I would make sure you update the version of pip you are using to 20.3.3.

@illume
Copy link
Member

illume commented Jan 2, 2021

Cool! Good to know. Let's close this now then.

(feel free to comment here if the new pip is still not working, and we can open it again)

@illume illume closed this as completed Jan 2, 2021
@BlueSage96
Copy link

BlueSage96 commented Jan 4, 2021 via email

@ghost ghost mentioned this issue Jan 6, 2021
@ghost
Copy link

ghost commented Jan 6, 2021

I am reoppening this because it dosen't seem to be 100% fixed yet...

@brittlizprice You say the fix dosen't work on M1 macs. Is it still not installing the wheel and trying to compile (and failing)?

@ghost ghost reopened this Jan 6, 2021
@BlueSage96
Copy link

BlueSage96 commented Jan 7, 2021

Yes. When I try to install pygame I get a compiler error. I wasn't able to install the wheel file either.
Image 1-3-21 at 8 19 PM

@Endogen
Copy link

Endogen commented Jan 12, 2021

Also can't install on MacBook Pro M1 with Python 3.9.1

sudo -H python3 -m pip install -U pygame --user
Collecting pygame
  Downloading pygame-2.0.1.tar.gz (5.5 MB)
     |████████████████████████████████| 5.5 MB 1.2 MB/s
    ERROR: Command errored out with exit status 1:
     command: /opt/homebrew/opt/python@3.9/bin/python3.9 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-oxsdbivr/pygame_2f9b4dc117f04901b27c382cdaf8275d/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-oxsdbivr/pygame_2f9b4dc117f04901b27c382cdaf8275d/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/tmp/pip-pip-egg-info-460u4d1_
         cwd: /private/tmp/pip-install-oxsdbivr/pygame_2f9b4dc117f04901b27c382cdaf8275d/
    Complete output (27 lines):


    WARNING, No "Setup" File Exists, Running "buildconfig/config.py"
    Using Darwin configuration...

    /bin/sh: sdl2-config: command not found
    /bin/sh: sdl2-config: command not found
    /bin/sh: sdl2-config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/tmp/pip-install-oxsdbivr/pygame_2f9b4dc117f04901b27c382cdaf8275d/setup.py", line 318, in <module>
        buildconfig.config.main(AUTO_CONFIG)
      File "/private/tmp/pip-install-oxsdbivr/pygame_2f9b4dc117f04901b27c382cdaf8275d/buildconfig/config.py", line 221, in main
        deps = CFG.main(**kwds)
      File "/private/tmp/pip-install-oxsdbivr/pygame_2f9b4dc117f04901b27c382cdaf8275d/buildconfig/config_darwin.py", line 131, in main
        [DependencyProg('SDL', 'SDL_CONFIG', 'sdl2-config', '2.0', ['sdl'])],
      File "/private/tmp/pip-install-oxsdbivr/pygame_2f9b4dc117f04901b27c382cdaf8275d/buildconfig/config_unix.py", line 39, in __init__
        self.ver = config[0].strip()
    IndexError: list index out of range

    ---
    For help with compilation see:
        https://www.pygame.org/wiki/MacCompile
    To contribute to pygame development see:
        https://www.pygame.org/contribute.html
    ---

    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

@Ropuh
Copy link

Ropuh commented Jan 15, 2021

Mac mini M1 also I can't install pygame:
`
rob@Mac-Robert ~ % sudo -H pip3 install pygame
Password:
Collecting pygame
Downloading pygame-2.0.1.tar.gz (5.5 MB)
|████████████████████████████████| 5.5 MB 1.4 MB/s
ERROR: Command errored out with exit status 1:
command: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-0b2nsb6v/pygame_4ffe8e44583c4264a7fd2d35574ae907/setup.py'"'"'; file='"'"'/private/tmp/pip-install-0b2nsb6v/pygame_4ffe8e44583c4264a7fd2d35574ae907/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /private/tmp/pip-pip-egg-info-uixh66ml
cwd: /private/tmp/pip-install-0b2nsb6v/pygame_4ffe8e44583c4264a7fd2d35574ae907/
Complete output (27 lines):

WARNING, No "Setup" File Exists, Running "buildconfig/config.py"
Using Darwin configuration...

/bin/sh: sdl2-config: command not found
/bin/sh: sdl2-config: command not found
/bin/sh: sdl2-config: command not found
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/tmp/pip-install-0b2nsb6v/pygame_4ffe8e44583c4264a7fd2d35574ae907/setup.py", line 318, in <module>
    buildconfig.config.main(AUTO_CONFIG)
  File "/private/tmp/pip-install-0b2nsb6v/pygame_4ffe8e44583c4264a7fd2d35574ae907/buildconfig/config.py", line 221, in main
    deps = CFG.main(**kwds)
  File "/private/tmp/pip-install-0b2nsb6v/pygame_4ffe8e44583c4264a7fd2d35574ae907/buildconfig/config_darwin.py", line 131, in main
    [DependencyProg('SDL', 'SDL_CONFIG', 'sdl2-config', '2.0', ['sdl'])],
  File "/private/tmp/pip-install-0b2nsb6v/pygame_4ffe8e44583c4264a7fd2d35574ae907/buildconfig/config_unix.py", line 39, in __init__
    self.ver = config[0].strip()
IndexError: list index out of range

---
For help with compilation see:
    https://www.pygame.org/wiki/MacCompile
To contribute to pygame development see:
    https://www.pygame.org/contribute.html
---

----------------------------------------

ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
rob@Mac-Robert ~ %
`

@robertpfeiffer
Copy link
Contributor

@Ropuh @Endogen @brittlizprice so do any of you actually have SDL2 installed?

I assume you do not, and the problem is just that there are no pre-built binary wheels for macos 11 on ARM.
Is there a pre-built SDL2 installer for mac os 11 on ARM? Do the downloads on libSDL.org work on ARM?

In the worst case, you have to compile SDL2 from source.

Maybe we could draft one of you into installing SDL2 and building a wheel from source...

@rajatyagi
Copy link

I have downloaded the latest version of sdl (2.0.14) using the command :
brew install sdl2 sdl2_gfx sdl2_image sdl2_mixer sdl2_net sdl2_ttf
but I am still facing the same issue on my M1 MacBook Air.
@robertpfeiffer how do we go about building the wheel from source?

@ankith26
Copy link
Contributor

ankith26 commented Jan 15, 2021

First make sure pip is on the latest version.
Then try this command
pip3 install https://github.com/pygame/pygame
This is going to make pip install the latest version from github, which is a few commits ahead of v2.0.1
The reason I’m suggesting that, rather than installing 2.0.1, is just to eliminate any pip related errors that happen while finding the right Mac wheels. That command will force pip to build pygame from source, and if your dependencies are all right, it’s gonna hopefully work :)

@robertpfeiffer
Copy link
Contributor

@rajatyagi I would try to find where sdl2-config is installed on your system and add that to $PATH, and barring that, find out where brew installed the SDL2 libraries and header files and report back here.

Based on what I know about homebrew (and I want to make it clear, I do not have an M1 mac or access to privileged information, all this is based on 5 minutes of googling), sdl2-config might be installed into /opt/homebrew/bin, but sdl2 can be installed on arm64 mac os with homebrew: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/sdl2.rb

So what you probably need to do is:

  1. make sure that you installed python/pip via the same method as SDL
  2. find where your install has put SDL2-config, add that location to your PATH if necessary like so: `export PATH="/opt/homebrew/bin:$PATH"
  3. install pygame via pip (be sure to use the right python install here, if you got SDL via macports or brew, use the python from macports or brew to install pygame)
  4. report back here

I wouldn't want to hardcode /opt/homebrew/bin inside setup.py case python is installed in /Library/Frameworks or /usr/local or /opt/ports

@robertpfeiffer
Copy link
Contributor

does installing SDL2 in /Library/Frameworks even install the sdl2-config command line program?

@rajatyagi
Copy link

The issue is resolved.
@robertpfeiffer you were right, I just followed the directions given by you
I found the SDL2-config file at:
/usr/local/bin/sdl2-config .
I added it to my path by:
export PATH=$PATH:/usr/local/bin/sdl2-config
finally I linked my python 3.9 with Homebrew using:
brew link python@3.9
then used the pip command to install pygame:
pip3 install pygame
Thanks for all the help!!

@robertpfeiffer
Copy link
Contributor

@rajatyagi It should be the directory, not the program itself. Are you telling me /usr/local/bin was not part of $PATH already on mac os 11? Or did brew link python@3.9 link python into /usr/local so you invoked the right pip?

In any case, if you get it to install with pip on one mac, you can run this:

git clone https://github.com/pygame/pygame.git
cd pygame
python3.9 setup.py -config -auto -sdl2
python3.9 setup.py bdist_wheel

to get a .whl file in the dist/ directory that can be installed on another mac (with the same OS and CPU arch) with pip.

Before more people post about their homebrew setup: This is not a homebrew/macports/autoconf support forum. As far as I can tell, the arm64 mac os currently has no binary wheel support, but that is a different issue from this one that was posted about x86.

We will may to open another issue for automatically binary wheels on mac os 11 with arm64 (Can we cross-compile? Does the CI run mac os?), but it seems to me that there is no problem actually compiling pygame if you have set up your system right.

@BlueSage96
Copy link

BlueSage96 commented Jan 17, 2021

I got this error. Should I uninstall & reinstall pip and pygame? Trying to install the homebrew (cannot unpack error) and I also tried Robert's suggestion and got an out of range error.

Image 1-17-21 at 4 33 AM

Image 1-17-21 at 4 36 AM

@robertpfeiffer
Copy link
Contributor

robertpfeiffer commented Jan 17, 2021

@brittlizprice In order to compile pygame, you need to install sdl2. You do not need to "reinstall pip" (I am probably misreading this. You can just use pip to upgrade pip. I do not think you need to uninstall and reinstall pygame via pip either). Right now, there are no binary pip wheels for pygame in arm64 mac os 11, so you have to compile your own sdl2 in order to compile pygame. Since there are no binary wheels for pygame yet, pip is attempting to compile pygame, but doesn't find the development files for SDL2.

You can either download the source from libSDL2.org, or install via homebrew. Macports and fink might also work, I don't know. I haven't used a mac in a decade. Compilation and installation of SDL2 development files needs to be done before you run pip install pygame.

In any case, the original bug reported here has been resolved. This is not a mac OS help forum, but a bug tracker.

I have created an issue with a task list for the mac os build situation.

@BlueSage96
Copy link

BlueSage96 commented Jan 17, 2021 via email

@BUCKFAE
Copy link

BUCKFAE commented Jan 18, 2021

The issue is resolved.
@robertpfeiffer you were right, I just followed the directions given by you
I found the SDL2-config file at:
/usr/local/bin/sdl2-config .
I added it to my path by:
export PATH=$PATH:/usr/local/bin/sdl2-config
finally I linked my python 3.9 with Homebrew using:
brew link python@3.9
then used the pip command to install pygame:
pip3 install pygame
Thanks for all the help!!

Works on my machine as well (MacBook Pro M1).

Adding sdl2 to the path was not required in my case, it worked out of the box after using brew to install sdl2.

However I still got an error installing pygame which was fixed by
brew reinstall freetype pkg-config

@ryanrudes
Copy link

ryanrudes commented Mar 4, 2021

Running brew reinstall freetype pkg-config worked for me, too

@Maxlanglet
Copy link

Maxlanglet commented Mar 4, 2021

Hello everybody, despite all of your help I couldn't install pygame. Maybe the reason is that my version of python is from mini forge and miniconda ? I don't know really since it usually doesn't cause problems. I can add that the sdl2-config file was not un /usr/local/bin but in something like /opt/homebrew/Cellar/..

@johnson7788
Copy link

@rajatyagi It should be the directory, not the program itself. Are you telling me /usr/local/bin was not part of $PATH already on mac os 11? Or did brew link python@3.9 link python into /usr/local so you invoked the right pip?

In any case, if you get it to install with pip on one mac, you can run this:

git clone https://github.com/pygame/pygame.git
cd pygame
python3.9 setup.py -config -auto -sdl2
python3.9 setup.py bdist_wheel

to get a .whl file in the dist/ directory that can be installed on another mac (with the same OS and CPU arch) with pip.

Before more people post about their homebrew setup: This is not a homebrew/macports/autoconf support forum. As far as I can tell, the arm64 mac os currently has no binary wheel support, but that is a different issue from this one that was posted about x86.

We will may to open another issue for automatically binary wheels on mac os 11 with arm64 (Can we cross-compile? Does the CI run mac os?), but it seems to me that there is no problem actually compiling pygame if you have set up your system right.

Same error, I am Mac M1, i do brew reinstall freetype pkg-config and build as your step, it works now. thanks!

@Ozzymandias0
Copy link

The issue is resolved.
@robertpfeiffer you were right, I just followed the directions given by you
I found the SDL2-config file at:
/usr/local/bin/sdl2-config .
I added it to my path by:
export PATH=$PATH:/usr/local/bin/sdl2-config
finally I linked my python 3.9 with Homebrew using:
brew link python@3.9
then used the pip command to install pygame:
pip3 install pygame
Thanks for all the help!!

Works on my machine as well (MacBook Pro M1).

Adding sdl2 to the path was not required in my case, it worked out of the box after using brew to install sdl2.

However I still got an error installing pygame which was fixed by
brew reinstall freetype pkg-config

Thanks. This worked on macbook air m1

@Raumss
Copy link

Raumss commented Jul 5, 2021

Here is my solution on Apple Silicon MacBook:
brew install sdl2 sdl2_gfx sdl2_image sdl2_mixer sdl2_net sdl2_ttf pkg-config
pip3 install pygame --pre

@serh11kalinin
Copy link

Here is my solution on Apple Silicon MacBook:
brew install sdl2 sdl2_gfx sdl2_image sdl2_mixer sdl2_net sdl2_ttf pkg-config
pip3 install pygame --pre

@Raumss big big thanks! worked for me!!!

@Vickko
Copy link

Vickko commented Jul 27, 2021

Running brew reinstall freetype pkg-config worked for me, too

It worked for me. Thanks!

@christianblandford
Copy link

Here is my solution on Apple Silicon MacBook:
brew install sdl2 sdl2_gfx sdl2_image sdl2_mixer sdl2_net sdl2_ttf pkg-config
pip3 install pygame --pre

Worked for me too on M1 Macbook Pro! Thanks so much.

@aleolux
Copy link

aleolux commented Oct 14, 2021

Here is my solution on Apple Silicon MacBook:
brew install sdl2 sdl2_gfx sdl2_image sdl2_mixer sdl2_net sdl2_ttf pkg-config
pip3 install pygame --pre

Thank you!!

@Laenpo
Copy link

Laenpo commented Feb 9, 2023

export PATH=$PATH:/usr/local/bin/sdl2-config
pip3 install pygame

I only used these two commands
It really works!
Thanks for the help!

@ferdavid1
Copy link

Here is my solution on Apple Silicon MacBook: brew install sdl2 sdl2_gfx sdl2_image sdl2_mixer sdl2_net sdl2_ttf pkg-config pip3 install pygame --pre

This helped me solve the same IndexError... compiling issue, on Cygwin for Win10.

@wesleyjesus-dev
Copy link

brew install sdl2 sdl2_gfx

Worked for me too on M1 Macbook Pro! Thanks so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests