michael-lazar / playscii

Fork of playscii
https://heptapod.host/jp-lebreton/playscii
MIT License
41 stars 5 forks source link

Is this version of Playscii intended to build on 64-bit versions of Mac OS? #3

Open BrendanJercich opened 2 years ago

BrendanJercich commented 2 years ago

Commentary on the Itch storefront seems to hint as much: https://itch.io/post/4747062 But I'm having trouble running it on Monterey/12.4. Specifically, I get the same error in response to python3 playscii.py on this repo that I do on the main repo from Heptapod, which is:

Traceback (most recent call last):
  File "/Users/brendan/Library/Mobile Documents/com~apple~CloudDocs/Code/playscii-source/env/lib/python3.9/site-packages/sdl2/sdlmixer.py", line 79, in <module>
    dll = DLL("SDL2_mixer", ["SDL2_mixer", "SDL2_mixer-2.0"],
  File "/Users/brendan/Library/Mobile Documents/com~apple~CloudDocs/Code/playscii-source/env/lib/python3.9/site-packages/sdl2/dll.py", line 194, in __init__
    raise RuntimeError("could not find any library for %s (%s)" %
RuntimeError: could not find any library for SDL2_mixer (PYSDL2_DLL_PATH: .)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/brendan/Library/Mobile Documents/com~apple~CloudDocs/Code/playscii-source/playscii.py", line 31, in <module>
    from sdl2 import video, sdlmixer
  File "/Users/brendan/Library/Mobile Documents/com~apple~CloudDocs/Code/playscii-source/env/lib/python3.9/site-packages/sdl2/sdlmixer.py", line 82, in <module>
    raise ImportError(exc)
ImportError: could not find any library for SDL2_mixer (PYSDL2_DLL_PATH: .)

I have no experience with SDL, so I'm fumbling in the dark here, but I have tried setting the PYSDL2_DLL_PATH environment variable to point to (eg) the sdl2dll directory tucked away in python3.9/site-packages in this copy of the code, which doesn't seem to affect anything.

Are you able to run Playscii on 64-bit Mac OS? Have you seen this issue before?

michael-lazar commented 2 years ago

Greetings

The only changes that I made regarding building on a mac were bumping some of the python dependency versions. This was a while ago, but IIRC the Pillow version was so old that I was having trouble building / finding wheels on pypi for that package.

https://github.com/michael-lazar/playscii/blame/master/requirements.txt

I'm currently running an M1 mac but I don't see any reason why this shouldn't work on 64-bit too. The installation notes that I wrote here are tailored to my specific environment and your homebrew directories or sdl version numbers might be different from mine.

I remember PYSDL2_DLL_PATH being a pain in the ass and finicky, and the key was that I had to create symlinks to the .dylib files and put them in the same directory.

https://github.com/michael-lazar/playscii/blob/2416e7438b993abd119a86b0fc1ffb1170eb33c3/NOTES.txt#L7-L8

I would double check that whatever your PYSDL2_DLL_PATH is set to, that directory contains both of these files with these specific names

BrendanJercich commented 2 years ago

OKAY! I had to tweak the paths to account for slightly different versions of the SDL libraries, and to account for my Homebrew libraries living in /usr/local/Cellar/, but after that following the instructions in the notes file actually launched the app from the command line. And I can add things to my virtual environment if I want to use them, too! Thank you very much!

bknoles commented 1 year ago

Using Python 3.10, I needed to bump numpy up to 1.21. The 1.20 version wouldn't build a wheel with Python 3.10. I didn't need to manually install Pillow either. My notes, based off this very helpful guide.

# Install packages needed for the app
brew install sdl2 sdl2_mixer numpy libjpeg libtiff

# Find the paths to the dylib files by running:
brew list sdl2
brew list sdl2_mixer

# Symlink the dylib files into the project directory
# (note: if you ever upgrade the sdl2 libraries the symlinks presumably need to be updated)
ln -s /path/to/libSDL2-2.0.0.dylib libSDL2.dylib
ln -s /path/to/libSDL2_mixer-2.0.0.dylib libSDL2_mixer.dylib

# Change numpy version in `requirements.txt` to something compatible with your Python version.
# For me, numpy==1.21.6 worked fine with Python 3.10.6

# Setup up a virtual environment and install the required packages
python3 -m pip venv venv
source venv/bin/activate
pip install -r requirements.txt

# Run the program, specifying the current directory with symlinked dylib file as the path to the sdl2 libraries
PYSDL2_DLL_PATH=. python playscii.py

# Enjoy!

Leaving this here for the next poor soul with Python 3.10 that's trying to make art for their terminal CLIs 😅

Thanks @michael-lazar !