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

Apple M1 support #17

Open
hiatsu0 opened this issue Feb 5, 2021 · 6 comments
Open

Apple M1 support #17

hiatsu0 opened this issue Feb 5, 2021 · 6 comments

Comments

@hiatsu0
Copy link

hiatsu0 commented Feb 5, 2021

A little unsure if this is really ialauncher's fault or something else related to the fact that Homebrew appears to have installed a bit newer version 3.9 of python3 under its folder in /opt/homebrew.

Previously I had ialauncher at ~/Library/Python/3.8/bin/ialauncher but after Homebrew installation as I tried to update it using pip3 install --upgrade ialauncher it went under /opt instead, and no longer starts due to some pygame/font.py issue below.

Maybe also worth noting, previously (due to issues getting Apple Silicon version of pygame) I used ialauncher via Rosetta x86 emulation and the previous version still runs just fine using Rosetta from `~/Library/Python/3.8/bin/ialauncher' but I'm no longer able to update/remove it using pip3. Now trying to run native Apple Silicon version of everything.

user@macbookair ~ % brew config
HOMEBREW_VERSION: 3.0.0
ORIGIN: https://github.com/Homebrew/brew
HEAD: ebc7cc36a0e029d58fac8cebd1b5ff583b3fd95b
Last commit: 9 hours ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 149d62524beea0231087f189a242fddc325adb3b
Core tap last commit: 42 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 12.0 build 1200
Git: 2.24.3 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 11.2-arm64
CLT: 12.4.0.0.1.1610135815
Xcode: N/A
Rosetta 2: false

user@macbookair ~ % which pip3
/opt/homebrew/bin/pip3
user@macbookair ~ % which pip 
/usr/local/bin/pip

user@macbookair ~ % pip3 install ialauncher
Collecting ialauncher
  Using cached ialauncher-2.2.1-py3-none-any.whl
Collecting pygame
  Using cached pygame-2.0.1-cp39-cp39-macosx_11_0_arm64.whl
Installing collected packages: pygame, ialauncher
Successfully installed ialauncher-2.2.1 pygame-2.0.1
user@macbookair ~ % which ialauncher
/opt/homebrew/bin/ialauncher
user@macbookair ~ % which dosbox
/opt/homebrew/bin/dosbox

user@macbookair ~ % ialauncher
pygame 2.0.1 (SDL 2.0.14, Python 3.9.1)
Hello from the pygame community. https://www.pygame.org/contribute.html
/opt/homebrew/lib/python3.9/site-packages/ialauncher/engine.py:96: RuntimeWarning: use font: cannot import name 'Font' from partially initialized module 'pygame.font' (most likely due to a circular import) (/opt/homebrew/lib/python3.9/site-packages/pygame/font.py)
(ImportError: cannot import name 'Font' from partially initialized module 'pygame.font' (most likely due to a circular import) (/opt/homebrew/lib/python3.9/site-packages/pygame/font.py))
  self.font = pg.font.SysFont(font_family, font_size)
Traceback (most recent call last):
  File "/opt/homebrew/bin/ialauncher", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/lib/python3.9/site-packages/ialauncher/__main__.py", line 20, in main
    Main(Loading(slurp_mode=args.slurp_mode), title='IA Launcher', fullscreen=options.fullscreen)
  File "/opt/homebrew/lib/python3.9/site-packages/ialauncher/engine.py", line 48, in __init__
    scene = scene.run(screen)
  File "/opt/homebrew/lib/python3.9/site-packages/ialauncher/engine.py", line 80, in run
    next_scene = self.update(screen)
  File "/opt/homebrew/lib/python3.9/site-packages/ialauncher/scenes.py", line 58, in update
    self.draw(screen, f'''
  File "/opt/homebrew/lib/python3.9/site-packages/ialauncher/engine.py", line 96, in draw
    self.font = pg.font.SysFont(font_family, font_size)
  File "/opt/homebrew/lib/python3.9/site-packages/pygame/__init__.py", line 59, in __getattr__
    raise NotImplementedError(missing_msg)
NotImplementedError: font module not available (ImportError: cannot import name 'Font' from partially initialized module 'pygame.font' (most likely due to a circular import) (/opt/homebrew/lib/python3.9/site-packages/pygame/font.py))
user@macbookair ~ %
@JaapJoris
Copy link
Member

JaapJoris commented Feb 5, 2021

Maybe also worth noting, previously (due to issues getting Apple Silicon version of pygame) I used ialauncher via Rosetta x86 emulation and the previous version still runs just fine using Rosetta from `~/Library/Python/3.8/bin/ialauncher' but I'm no longer able to update/remove it using pip3. Now trying to run native Apple Silicon version of everything.

This issue is definitely related to the installation of pygame on Apple-designed processors. IA Launcher uses pygame's font module, which will throw this error if there is no binary compiled for your architecture.

Until this module has been successfully ported to the new architecture, the only way to run IA Launcher is by using Rosetta.

You can check whether your installation of pygame has a working font module with the following command:

$  python3 -c 'import pygame; pygame.font.init()'

@hiatsu0
Copy link
Author

hiatsu0 commented Jun 14, 2021

A small update to this Apple M1 issue, after discovering at pygame that a particular version does indeed install on M1 Macs successfully. Now the font module seems to be working:

➜  ~ python3 -c 'import pygame; pygame.font.init()'
pygame 2.0.0.dev6 (SDL 2.0.14, python 3.9.5)
Hello from the pygame community. https://www.pygame.org/contribute.html
➜  ~ 

But ialauncher still crashes with some BMP issue after it has loaded a little over 2000 titles:

➜  ~ pip3 install pygame==2.0.0.dev6 --no-cache-dir
Collecting pygame==2.0.0.dev6
  Downloading pygame-2.0.0.dev6.tar.gz (3.7 MB)
     |████████████████████████████████| 3.7 MB 5.1 MB/s 
Building wheels for collected packages: pygame
  Building wheel for pygame (setup.py) ... done
  Created wheel for pygame: filename=pygame-2.0.0.dev6-cp39-cp39-macosx_11_0_arm64.whl size=2519402 sha256=e1267c6c1c67f5222f3bd944d8c069a02cce96f374befac917eb208ceb7a17a7
  Stored in directory: /private/var/folders/4p/x25zqqtd5mb8c3g2r1cq1w600000gn/T/pip-ephem-wheel-cache-j1m4go2p/wheels/db/50/b4/f7f8f8ac5c2340f48135de75fff62be54611ef8db11267bf3f
Successfully built pygame
Installing collected packages: pygame
Successfully installed pygame-2.0.0.dev6

➜  ~ pip3 install ialauncher --no-cache-dir                       
Collecting ialauncher
  Downloading ialauncher-2.2.1.tar.gz (49.9 MB)
     |████████████████████████████████| 49.9 MB 11.8 MB/s 
Requirement already satisfied: pygame in /opt/homebrew/lib/python3.9/site-packages (from ialauncher) (2.0.0.dev6)
Building wheels for collected packages: ialauncher
  Building wheel for ialauncher (setup.py) ... done
  Created wheel for ialauncher: filename=ialauncher-2.2.1-py3-none-any.whl size=50908254 sha256=ad82aecb6887e01555c1fc56c15522a51bfa6166257ce3db4cc9c92697e040cf
  Stored in directory: /private/var/folders/4p/x25zqqtd5mb8c3g2r1cq1w600000gn/T/pip-ephem-wheel-cache-1i8kwxgz/wheels/c0/a3/5c/820965c325d953f2f03f0434850505e2f92451edb3686c6af1
Successfully built ialauncher
Installing collected packages: ialauncher
Successfully installed ialauncher-2.2.1

➜  ~ ialauncher 
pygame 2.0.0.dev6 (SDL 2.0.14, python 3.9.5)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "/opt/homebrew/bin/ialauncher", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/lib/python3.9/site-packages/ialauncher/__main__.py", line 20, in main
    Main(Loading(slurp_mode=args.slurp_mode), title='IA Launcher', fullscreen=options.fullscreen)
  File "/opt/homebrew/lib/python3.9/site-packages/ialauncher/engine.py", line 48, in __init__
    scene = scene.run(screen)
  File "/opt/homebrew/lib/python3.9/site-packages/ialauncher/engine.py", line 80, in run
    next_scene = self.update(screen)
  File "/opt/homebrew/lib/python3.9/site-packages/ialauncher/scenes.py", line 104, in update
    image = self.games.get_image()
  File "/opt/homebrew/lib/python3.9/site-packages/ialauncher/gamelist.py", line 25, in get_image
    game.cached_image = pg.image.load(game.get_titlescreen())
pygame.error: File is not a Windows BMP file
➜  ~ 

@JaapJoris
Copy link
Member

JaapJoris commented Jun 14, 2021

Hi there, and thanks for the update! Very interesting that you got pygame somewhat working using the particular version pygame==2.0.0.dev6, but too bad that it then throws a File is not a BMP file error.

The pygame error is technically correct, all included files are PNG files and not BMP files. I found a pygame bug report which seems to address this particular issue: pygame/pygame#2458

Maybe you could try installing libpng using Brew and than compiling pygame from source using the following commands (You will probably need to install other build dependencies as well):

brew install libpng libjpeg
pip install pygame --no-binary pygame

Someone in the comment thread of the issue I linked to above seemed to get a fork of pygame working on M1 with the following commands:

brew install sdl2 sdl2_mixer sdl2_gfx sdl2_image sdl2_net sdl2_ttf
brew reinstall freetype pkg-config
# git clone https://github.com/pygame/pygame.git
git clone https://github.com/nelsonlove/pygame.git
cd pygame
python setup.py -config -auto -sdl2
python setup.py bdist_wheel
python setup.py install --record installed-files.txt

Personally, I don't see why building the original pygame from source on an M1 wouldn't work, but then again I've never tried it.

@JaapJoris
Copy link
Member

Finally, a little assurance: besides DOSBox, the only dependency of IA Launcher is pygame, so if you somehow get that to work on M1 than IA Launcher should work as well. Keep us updated!

@hiatsu0
Copy link
Author

hiatsu0 commented Jul 22, 2021

Can confirm I got pygame and thus ialauncher working natively on M1 Mac using the nelsonlove pygame fork and compile instruction above. Though for some reason I had to use python3 instead of python or else I would get this permission error in the last step:

The following error occurred while trying to add or remove files in the installation directory:

    [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-54700.write-test'

The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was:

    /Library/Python/2.7/site-packages/

Using python3 it installed into /opt/homebrew/lib/python3.9/site-packages/pygame-2.0.2.dev1-py3.9-macosx-11-arm64.egg instead. (Don't really understand the differences with homebrew's python3 and Mac's native python..)

So for me the winning recipe was:

brew install sdl2 sdl2_mixer sdl2_gfx sdl2_image sdl2_net sdl2_ttf
brew reinstall freetype pkg-config
git clone https://github.com/nelsonlove/pygame.git
cd pygame
python3 setup.py -config -auto -sdl2
python3 setup.py bdist_wheel
python3 setup.py install --record installed-files.txt

@JaapJoris
Copy link
Member

JaapJoris commented Jul 29, 2021

Awesome! You did a great job figuring all of this out! I'm leaving this issue open until Apple M1 supports regular pygame, but I'll make sure to direct any future inquiries to your solution.

@JaapJoris JaapJoris changed the title ialauncher not starting anymore after installing Homebrew [macOS, Apple Silicon] Apple M1 support Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants